Null value types? (requires an expert of genius proportions)
Posted on 2004-10-12
.NET offers value types to describe primitive values such as int, boolean, double, etc. But there is no reference types of offered - I see this as problematic because I am unable to represent a primitive variable as null. I realize I can box a value type, but then I lose type safety.
For example - if I had a "Person" object with an "Age" property that returned an Int32 - I cannot set the "Age" to null. So if, for example, a user chose NOT to provide their age I would have to set it to some arbitrary value that I could interpret as "not set", such as -1. But then, every bit of code that needs to determine whether "Age" was "set" would have to know that "-1" is the magic number that means "not set".
To resolve this I have created my own reference type implementations of the .NET primitives. And, although they solve my problem, it is a drag that I use my proprietary solution rather than Microsoft offering a more global solution.
I'm hoping that my problem is a result of my lack of understanding of .NET. Otherwise, I'll be really disappointed in Microsoft (again) :(