Dennis,
As I stated it allows DBNull to be treated differently then Nothing. A
second reason is to allow your code to avoid Nothing itself.
Remember DBNull is simply an implementation of the Special Case pattern.
http://martinfowler.com/eaaCatalog/specialCase.html
It allows you to write code that you know will always have a value, so you
are able to call any of its base methods (in this case Object).
For example I know I can call ToString on each value returned from
DataRow.Item() as those items will never be Nothing. If one of the values
could be Nothing I would need special case code to call Object.ToString...
Yes DBNull may require special case codes in spots, I'm not disputing
that...
To go farther, why
doesn't a string variable used like b.Trim return nothing when b is
nothing
instead of an exception?
Unlike C++, VB.NET & C# requires an object be present when you call an
instance method on that object. IMHO at a certain "OO" level it doesn't
really make sense to ask an object to perform some behavior when there is no
object there to ask do to anything...
Unmanaged C++ (I'm not sure about managed C++) does allow calling instance
methods on null (Nothing) pointers causing this (Me) to be null (Nothing).
However it normally required a lot of "AssertValid" macros in your code to
ensure that you actually have an object that you are calling a method on. In
other words 99% or better of code requires a valid object, and one or two
methods could benefit from being Nothing...
Everytime you want to trim a string, you have to
check it for being nothing unless
I rarely check a variable for being nothing before I call instance methods &
I rarely receive NullReferenceExceptions, as I make sure variables are
initialized, I normally have strategic Guard conditions or use the Null
Object Pattern to prevent variables from being Nothing. This is not to say I
don't receive NullReferenceExceptions during development, its just that they
are "limited"...
Current versions of C# & VB.NET 2005 will issue compile warnings if you try
to call an instance method on an un-initialized variable (the most common
reason for NullReferenceExceptions).
Hope this helps
Jay