Search code examples
c#dbnull

What Is DBNull Needed For Anyway?


Possible Duplicate:
What is the point of DBNull?

Since the beginning of my adventure with .NET I have always asked myself one question:

why do we need the DBNull type? Is a simple null reference not enough?

MSDN says that DBNull "Represents a nonexistent value". From a logical point of view - this one sentence explains why a null reference cannot be used - because it is a null reference and not a lack of value. But is it enough to introduce a type that causes a lot of trouble?

BTW: If anyone has something to say in defense of the DBNull I would really appreciate it.


Solution

  • DBNull has existed since the earliest versions of .Net framework.

    Nullable value types (Nullable<T>) has only existed since version 2 of the framework.

    Since, before version 2, it was possible to receive, say, a null int value back from the database, how would you propose it be represented? Then, for consistency, the same was used to represent all DB nulls, whether they translated to a value or reference type.