Moderately Clever .NET Trick #1

September 22, 2007 by Craig

System.Nullable is an autoboxing wrapper that brings support for null values to types that normally don’t support null (like int). Not allowing nulls for value types in the first place is a bit of a pest (although I won’t elevate it to the level of “Stupid .NET Trick”, as I think there’s at least some legitimate reasoning behind it). System.Nullable is a hack to work around that but it’s relatively clean: You can use the wrapper class directly, or you can simply suffix your variable with a “?” (thus you get “int? x = null”, which nicely indicates that the variable is not your standard int).


No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment