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

后端 未结 30 2443
礼貌的吻别
礼貌的吻别 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:37

    I prefer to use:

    if (IsGood)
    {
        DoSomething();
    }
    

    and

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

    as I find this more readable - the ! is just too easy to miss (in both reading and typing); also "if not IsGood then..." just doesn't sound right when I hear it, as opposed to "if IsGood is false then...", which sounds better.

提交回复
热议问题