Should I use `!IsGood` or `IsGood == false`?

后端 未结 30 2496
礼貌的吻别
礼貌的吻别 2020-12-02 19:49

I keep seeing code that does checks like this

if (IsGood == false)
{
   DoSomething();
}

or this

if (IsGood == true)
{
   D         


        
30条回答
  •  南笙
    南笙 (楼主)
    2020-12-02 20:42

    I've seen the following as a C/C++ style requirement.

    if ( true == FunctionCall()) {
      // stuff
    }
    

    The reasoning was if you accidentally put "=" instead of "==", the compiler will bail on assigning a value to a constant. In the meantime it hurts the readability of every single if statement.

提交回复
热议问题