Possible Duplicate:
C# okay with comparing value types to null
The behaviour described below is specific to .net-3.5 only
Hello,
I just ran across the most astonishing behavior in the C# compiler;
I have the following code:
Guid g1 = Guid.Empty;
bool b1= (g1 == null);
Well, Guid is not nullable therefore it can never be equal to null. The comparison i'm making in line 2 always returns false.
If you make the same thing for an integer, the compiler issues an warning saying the result will always be false:
int x=0;
bool b2= (x==null);
My question is: Why does the compiler lets you compare a Guid to null?
According to my knowledge, it already knows the result is always false.
Is the built-in conversion done in such a way that the compiler does assume null is a possible value?
Am I missing anything here?
Thanks, Luís