2014-01-29 40 views
-3

我对这种将条件分配给布尔变量的这种方式真的很陌生。如何直接使用条件分配一个布尔变量

比方说,我有这样的

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; 

如何直接分配型布尔这种状况呢?优化或更好的方式。

+1

@CodeCaster:所以再次感谢你:)干杯 – Learner

回答

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))) 
+0

谢谢,给出了一些错误“唯一的任务是可能的” – Learner

+0

@Divine然后在网上搜索的** **确切的错误。此外,你要求_“优化或更好的方式”_,这是一个错误的问题。没有优化,这是纯粹的化妆品。 – CodeCaster

+0

谢谢你,我的坏,你是上帝帮助我,但是当我上次做同样的事时,它给了我一些愚蠢的错误。现在它不是:0 – Learner

相关问题