|
Null and DbNull are two different things, and given that most of what I work with ends up persisting to a database where DbNull has meaning and relevance, I find myself dealing with how a DbNull is represented to the user (not to mention internally). It's a shame that there isn't better coupling between C#'s nullable types and the DB persistence framework. What I'd like to see is more thought put into the entire issue of database, internal, and UI representation of nullable fields and default values and how they are handled. As it is, I have to write code to do all that manually, which is fine, but it seems like it's something that the C# language and .NET framework could address.
Marc
Thyme In The CountryPeople are just notoriously impossible. --DavidCrow There's NO excuse for not commenting your code. -- John Simmons / outlaw programmer People who say that they will refactor their code later to make it "good" don't understand refactoring, nor the art and craft of programming. -- Josh Smith
|
|
|
|
|
Yes, I expected the new Nullable type to be able to deal with DbNull but was surprised it couldn't.
Kevin
|
|
|
|
|
it depends on the situation. Sometimes you are using and object instance that doesn't have an "Empty" value so its easier to use null value instead. Also null value may help you find out that the variable has not been used or isn't needed anymore.
|
|
|
|
|
There are many situations where is needed to know if we deal with no value or empty. I mean, sometimes a user has selected empty value for an option, and in this case no default value comes into place. It's not the same case when the same user has made no selection at all, this time, a null value is handy.
|
|
|
|
|
Especially with HANDLE s or other handle types (like HKEY ), it's nice to have NULL or INVALID_HANDLE_VALUE as a sentinel to indicate that no clean-up is necessary.
|
|
|
|
|
On the other hand, the absence of a handle (as opposed to storing a NULL value), is an information carrier as well. It all depends on what meaning you assign to NULL. If you're caching handles, the absence of a handle could for instance mean that the corresponding socket is not connected, non-NULL values mean live sockets, and NULL values indicate pending socket connections. (This is actually a bad example, as such states should probably be indicated by means of enums - but you get the point).
--
-= Proudly Made on Earth =-
|
|
|
|
|
there may be situations when you want to fake a null value (aka:more than 1 kind of a null value)
|
|
|
|