January 2, 2008

.NET Compiler bug? (Update)

I have a typed DataTable (called FactTable) that gets data from a table in SQL server where a Date field can be null.

So I have created a System.Nullable variable in my code:
Datetime? emailDate;

And a typed DataRow from my DataTable:
MyDataSet.FactRow factRow = factTable.Rows[0];

Why does this NOT WORK:
emailDate = factRow.IsEmailDateNull() ? null : factRow.EmailDate;

But this works:
if (factRow.IsEmailDateNull())
emailDate = null;
emailDate = factRow.EmailDate;

Compiler error is: Type of conditional expression cannot be determined because there is no implicit conversion between '' and 'System.DateTime'

Remember: My variable is nullable!!!

David defined this problem as a feature. But aren't both examples the same? Isn't this just a compile thing to convert from the first example to the second one?
I think it has to do something with nullable types, because with string or byte[] it works like a charm:
string title = factRow.IsTitleNull() ? null : factRow.Title;
byte[] picture = factRow.IsPictureNull() ? null : factRow.Picutre;