******************* Type 1 ***********************
int iUnits;
int iStock ;
if (iStock== null)
{
iUnits= 0;
}
else
{
iUnits= (int)iStock;
}
******************* Type 2 ***********************
// using the coalesce operator, ??,
int iUnits= iStock ?? 0;
The coalesce operator works like this: if the first value (left hand side) is null, then C# evaluates the second expression (right hand side).
int iUnits;
int iStock ;
if (iStock== null)
{
iUnits= 0;
}
else
{
iUnits= (int)iStock;
}
******************* Type 2 ***********************
// using the coalesce operator, ??,
int iUnits= iStock ?? 0;
The coalesce operator works like this: if the first value (left hand side) is null, then C# evaluates the second expression (right hand side).
No comments:
Post a Comment