我真的很擅长将这个条件赋给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类型中直接指定此条件?优化或更好的方式。
答案 0 :(得分:1)
只需将您的变量分配给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)))