Six of one, half of something useful on the other
I’m a little unimpressed with Nullable types in C# 2.0. It is certainly advantageous and time saving to have the ability to treat any value type in C# as if it were a reference type while simultaneously retaining the ability to keep it on the stack. It would be more advantageous, however, if at run time I had the ability to tell if the newly Nullable variable was declared Nullable.
I don’t because of the manner in which Nullable types were implemented. Take the following code, for instance:
Also, a personal shout out to Stephen Colbert. Lincolnish, indeeed.
I don’t because of the manner in which Nullable types were implemented. Take the following code, for instance:
Nullable<int> meaningOfLife = 42;Alternately, I can rewrite it as such:
bool isNullableInt = meaningOfLife is Nullable<int>; //true
bool isInt = meaningOfLife is int; // true
int meaningOfLife = 32;Nullable<int> and int look the same at runtime, and there is no way to tell which of the two a variable was declared as if you did not already know beforehand. The issue here is that I can imagine at least a few cases where I would want to be able to tell if a value type variable was declared Nullable. There must have been some other way to implement this that would have granted me this functionality.
bool isNullableInt = meaningOfLife is Nullable<int>; // true
bool isInt = meaningOfLife is int; // true
Also, a personal shout out to Stephen Colbert. Lincolnish, indeeed.

0 Comments:
Post a Comment