I pierced this in LinqPad:
var t = new DateTime(); t.Dump(); (t == null).Dump();
And got the following:
IL_0000: ldloca.s 00 IL_0002: initobj System.DateTime IL_0008: ldloc.0 IL_0009: call LINQPad.Extensions.Dump IL_000E: pop IL_000F: ldc.i4.0 IL_0010: call LINQPad.Extensions.Dump
So yes, the compiler compiles it the same way:
var t = new DateTime(); t.Dump(); (false).Dump();
I wonder if I create my own structure ( TestStruct ) and try this:
TestStruct t; (t == null).Dump();
... the compiler complains that I cannot perform an equal comparison between TestSruct and null .
Update
In a comment, Paolo points to another StackOverflow post reporting this latest phenomenon. Apparently, overloading the == and != Operators, the type of the value is automatically converted from t == null to (Nullable<TestClass>)t == (Nullable<TestClass>)null . If you did not overload these statements, this implicit conversion does not make sense, so you will receive an error message.
source share