我确实对这种将条件分配给bool变量的风格很陌生。
举例来说,我有这个
bool type;
if (((sDataSet.Shipment[0].CI_TYPE == Constants.ShipType.CI_R) &&
(shipType == Constants.ShipType.CI_R)) ||
((sDataSet.Shipment[0].CI_TYPE == Constants.ShipType.CI_P) &&
(shipType == Constants.ShipType.CI_R)) ||
((sDataSet.Shipment[0].CI_TYPE == Constants.ShipType.CI_R) &&
(shipType == Constants.ShipType.CI_P)))
type = true;
else
type = false;
如何在bool类型中直接分配此条件?优化或更好的方法。
只需将变量分配给if语句,然后删除if。像这样:
type = (((sDataSet.Shipment[0].CI_TYPE == Constants.ShipType.CI_R) &&
(shipType == Constants.ShipType.CI_R)) ||
((sDataSet.Shipment[0].CI_TYPE == Constants.ShipType.CI_P) &&
(shipType == Constants.ShipType.CI_R)) ||
((sDataSet.Shipment[0].CI_TYPE == Constants.ShipType.CI_R) &&
(shipType == Constants.ShipType.CI_P)))
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句