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
!