So I have a bool variable like this in model.
bool Foo;
I am receiving data from server and de-serialize it model object. So whatever fields are not there in server data gets initialized to defaults. And default(bool)
is false.
But value false
is also an acceptable value for my variable Foo
. So is there some way to check if it gets value false
from server or its default.
I also have same issue with other types like int, double etc. which doesn't defaults to null.
In your place, I'd use Nullable<bool>
(bool?
) to your purposes. Then you will be able to check value in this way:
bool? Foo;
if(Foo.HasValue)
{
// do something with Foo.Value
}
else
{
// Foo is uninitialized
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With