Kirk Marple

Musings of a Yukon and Whidbey pioneer... and feeling the arrows in my back...

<July 2008>
SuMoTuWeThFrSa
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789


Navigation

Subscriptions

Post Categories



Tuesday, January 18, 2005 - Posts

New C# 2.0 fact of the day...
I started using Nullable<T> types today for the first time. I found a great use for them - a better default state for API properties. For example, instead of using -1 for the default value for integers, i now use Nullable<int> and set the default to null. Makes it easier to differentiate between null as "initialized" and null as what the caller actually set.

Another key point - i found the Nullable class, and there are some very useful helper methods in there. I needed to use Nullable.Unwrap(o) to grab the inner value from the nullable object. I had a case where i was using reflection to lookup property values, and they were nullable types. So, i had to use the Nullable.Unwrap method to pull out the actual value before using it. If the value was null, then i would skip it.

Cool, eh?

posted Tuesday, January 18, 2005 7:44 PM by kmarple with 4 Comments




Powered by Dot Net Junkies, by Telligent Systems