Alex Rivera | Logout

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

Asked 2010-03-17T16:41:12.757
22

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

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

Obviously the condition will never be satisfied..

Edit
Report

1 Answer

2

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.

answered 2010-03-17T16:45:09.267

Your Answer