I'll forever chuckle when I read that title. Maybe you will too after you read this.
I was aware of the Nullable generic struct in the 2.0 CLR, but I only just now figured out that they've built direct support for it into C# 2.0. This is awesome! At work, we currently have a whole bunch of structs that add null support to the value types in the CLR. So we have NullableSingle, NullableDouble, NullableUInt64, etc. This helps us incredibly to match the database concept of numbers and such that can have null values.
I've been looking forward to Nullable for some time, but now I'm absolutely ecstatic about the C# support for it. Using the magic question mark, I can declare a value type to be nullable. For instance:
bool? hasHairOnHead = false;
Now you get the title joke, right? This means that hasHairOnHead can be set to null, not just through Nullable's HasValue method, but by actually setting it to null:
hasHairOnHead = null;
Freaking awesome, eh? So now, the Headless Horseman's hasHairOnHead value can more accurately express his status. (OK, it was the first example I thought of). The same goes for null comparisons and such!
Of course now I'll get confused reading documentation...Is that a question or a nullable type? Just try to decipher this faq: Why don't nullable relational operators return bool? instead of bool?
That little question mark is going to save me alot of headaches. Now I just have to wait for it to be out of beta.
Remember Me
Page rendered at Tuesday, October 14, 2008 8:18:58 AM (Pacific Standard Time, UTC-08:00)
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.