Hi -
The use you state is valid.
They really come into their own when data needs to be able to identify when
it isn't holding a value. In SQL a statement could return a value or it
could return NULL. This doesn't cause too much problem for reference types
but obviously a value type needs a value (not unreasonable); this is where
the problem occurs.
You could assign an arbitrary NULL value (say 0) but it doesn't really model
NULL correctly as it's obviously in the range that the value holds.
Nullable types are created by the generic template struct Nullable and all
they essentially do is to maintain a boolean alongside the value indicating
whether it has been assigned to or not.
HTH
- Andy
"Mike P" <mi*******@gmail.comwrote in message
news:Ot**************@TK2MSFTNGP03.phx.gbl...
What are nullable types used for? The only use I can think of is where
I have a method like this where some values being passed to it may be
null :
public int AddUser(int? UserRegion, string UserName etc)
You might have an Add User page where some of the fields do not have a
value entered by the user, so you can account for this by making these
types nullable in the method above. Is this the right usage of nullable
types? And what are the other uses?
*** Sent via Developersdex http://www.developersdex.com ***