Developers blog, .NET, C#, VB.NET, ATLAS, AJAX, WWF, ORM, LINQ, ARCHITECTURE and more by Frank Kroondijk
vrijdag, december 16, 2005
to null or not to null, c# 2.0 makes it possible
recently I had a discussion of how to handle null variables/datafields. Personally I always tried to avoid these cases but now C# 2.0 has a new feature, called nullable type. Look at the next sample:
myInt = null;
myInt = System.Conver.ToInt32(dbReader["whatever"]);
Bassically myInt is a simple struct with a bit flag to check 4 null...
nice clean solution i guess..
!! note the question mark !! > int?
note: try to write more articles in english, for a bigger audiance :-)
- edit -
dim myInt as Nullable(Of Integer)
myInt = nothing
if myInt.equals(nothing) then
not so smooth as the C# flavour, more homegrown style :-(