byte b = 14;
object o = b;
int? i = (o as int?);
i is null, and now i.Value fails, and GetValueOrDefault returns default.
This is weird because a cast from a byte to an int or backwards is always valid. A byte *is* an int. Apparently this isn't the same for nullables.
So watch out what types your data readers and whatnot are actually returning.
(Note: this is happening because of a crazy stored procedure returning TINYINT when it should have been BIT, or even INT)
Wednesday, November 18, 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment