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

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

    The !IsGood pattern is eaiser to find than IsGood == false when reduced to a regular expression.

    /\b!IsGood\b/
    

    vs

    /\bIsGood\s*==\s*false\b/
    /\bIsGood\s*!=\s*true\b/
    /\bIsGood\s*(?:==\s*false|!=\s*true)\b/
    

提交回复
热议问题