Possible Duplicate:
C# okay with comparing value types to null
Why does C# allow :
class MyClass
{
public int MyInt;
}
static void Main(string[] args)
{
MyClass m = new MyClass();
if (m.MyInt == null) // <------------- ?
Console.Write("......");
}
Resharper says “expression is always false” – which is obviously – true since MyInt is int and not int?
But how C# allow this to compile? The property will always be there and its type is int!
I think, this is simply for the same reason why would compile
Something that would never execute.
Worth mantioning that, yes you don’t get error, but you get a warning on this.