We just ran across some bad code like this in our c#.net 4 codebase
DateTime myDate = someValue;
If (myDate==Null)
Do Something
It occurred to us that this condition will never occur.
How does the compiler handle these non-nullable struct comparisons?
Originally we were surprised that it would compile... but rationalized it on the point that you could certainly have a constant comparison like:
If(1==2)
Which would also never resolve true... but in that case the compiler can easily tell they are constants. Does it optimize or rollup non-nullable comparisons?