E
Earl Teigrob
One of the few things about C# that drives me crazy is that I can not assign
a null value to a primitive data type such as "int" or "DateTime". There are
just so many times when I want to specify one of these types with "no valid
data" but it always must contain some valid value. In some cases I box and
unbox them as object types so that I can assign then a null value, but then
I lose the strong type casting of C#. From a technical point of view I
understand why this is the case and realize that it would probably take
unacceptable overhead for the language to be written so that primitive types
can accept a null values, but it would sure make my programming life easier!
I am thinking of using something like int.MinValue and DateTime.MinValue as
my own "null" value and test for these when I want to know if valid data
exist. If I do not know that data type before testing for my new null
conditions, I thought I could create my own NullData class and use
overloaded operators == and != that would test for my own set of null
conditions, based on the type that was being tested.
Does anyone have a way that they deal with this issue or seen any articles
that address this? I'm know I'm not the first one to tackle this!!!
Thanks for you feedback
Earl
a null value to a primitive data type such as "int" or "DateTime". There are
just so many times when I want to specify one of these types with "no valid
data" but it always must contain some valid value. In some cases I box and
unbox them as object types so that I can assign then a null value, but then
I lose the strong type casting of C#. From a technical point of view I
understand why this is the case and realize that it would probably take
unacceptable overhead for the language to be written so that primitive types
can accept a null values, but it would sure make my programming life easier!
I am thinking of using something like int.MinValue and DateTime.MinValue as
my own "null" value and test for these when I want to know if valid data
exist. If I do not know that data type before testing for my new null
conditions, I thought I could create my own NullData class and use
overloaded operators == and != that would test for my own set of null
conditions, based on the type that was being tested.
Does anyone have a way that they deal with this issue or seen any articles
that address this? I'm know I'm not the first one to tackle this!!!
Thanks for you feedback
Earl