Kirk Marple

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

<September 2008>
SuMoTuWeThFrSa
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011


Navigation

Subscriptions

Post Categories



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 on Tuesday, January 18, 2005 7:44 PM by kmarple


# re:New C# 2.0 fact of the day... @ Monday, April 11, 2005 5:28 AM

^_^,Pretty Good!

kmarple

# re:New C# 2.0 fact of the day... @ Monday, April 11, 2005 9:37 PM

^_^,Pretty Good!

kmarple

# re:New C# 2.0 fact of the day... @ Friday, April 15, 2005 10:13 AM

^_^,Pretty Good!

kmarple

# re:New C# 2.0 fact of the day... @ Monday, May 16, 2005 10:14 AM

^_~,pretty good!csharpsseeoo

kmarple




Powered by Dot Net Junkies, by Telligent Systems