Does anyone have concrete information on how C# handles comparisons with Nullable<T> types when one side of the comparison is null?
As I understand from experimenting with the compiler, it seems that the comparison always returns false, but I can’t find any documentation to back that up. Is this a real feature of the language (and thus something I can count on), or is this an implementation detail that might change in future versions?
In other words, does the following method returning true imply y.HasValue, and can you point me to some documentation that proves that it does?
public bool foo(int x, int? y)
{
return x < y;
}
Yes – the C# language specification, section 7.3.7. In this case, it’s a relational operator:
There are similarly detailed sections for other operators.
When in doubt about how some aspect of the language works (and whether it’s guaranteed or implementation-specific), the C# language specification should be your first port of call.