Several things:
Age
is not an integer - it is a nullable integer type. They are not the same. See the documentation for Nullable<T>
on MSDN for details.
??
is the null coalesce operator, not the ternary operator (actually called the conditional operator).
To check if a nullable type has a value use HasValue
, or check directly against null
:
if(Age.HasValue)
{
// Yay, it does!
}
if(Age == null)
{
// It is null :(
}