Why doesn't the compiler at least warn on this == null

后端 未结 5 1094
傲寒
傲寒 2020-12-14 17:56

Why does the C# compiler not even complain with a warning on this code? :

if (this == null)
{
   // ...
}

Obviously the condition will

5条回答
  •  被撕碎了的回忆
    2020-12-14 18:30

    This also falls in line with other warnings C# does (or not does for that matter) like:

    if(true)
    or 
    if(1 == 1)
    

    These will also always have the same result no matter what.

提交回复
热议问题