I have got an integer value and i need to check if it is NULL or not. I got it using a null-coalescing operator
C#:
public int? Age;
if ((Age ?? 0)==0)
{
// do somethig
}
Now i have to check in a older application where the declaration part is not in ternary. So, how to achieve this without the null-coalescing operator.
Nullable<T>(or?) exposes aHasValueflag to denote if a value is set or the item is null.Also, nullable types support
==:if (Age == null)The
??is the null coalescing operator and doesn’t result in a boolean expression, but a value returned:So for your example:
Or:
Or:
Or ternary: