See, my problem is I'm using it like this:
public int iChildrenCount{
get{
setValueFromDB(localiChildrenCount, colIndexToGet);
return Convert.ToInt32(localiChildrenCount);
}
set{
localiChildrenCount = value;
}
}
So, the compiler won't generate an error, and I won't know if the value
returned when I reference iChildrenCount is 0 or null.
Also, I have no way of removing whatever value is currently in
iChildrenCount. For example, iChildrenCount is a database field
corresponding to the question "How many children do you have?" and it allows
nulls in the database. The user can come back later and edit the form and
should have the option of not specifying a value or removing the answer they
previously specified. So, if they previously answered 3, and now they
remove that value, when I set iChildrenCount, I later won't know if the
answer to the question is 0 or not specified (at least not without
referencing the control on the form). In a case like that I can set not
specified to -1, but in other examples, -1 is a valid answer.
How do people ussually overcome this with out writing ugly code that does a
bunch of checks?
"John Smith" <js@no.com> wrote in message
news:Ok**************@TK2MSFTNGP10.phx.gbl...
Hey folks,
I know this is an old topic, but I can't find a definitive answer on
google.
How do I tell if an int has been initialized or not? I had been testing
it like:
if(myInt == Convert.ToInt32(null)){
:
}
But now I just realized that this is true:
Convert.ToInt32(null) == Convert.ToInt32(0)
and since myInt may contain 0 as a value, this won't work. So, how do you
do it? I'm starting to miss the simple good old days of
if(myInt == null)