What does ?? mean in C#?

Possible Duplicate:
What do two question marks together mean in C#?

What does the ?? mean in this C# statement?

int availableUnits = unitsInStock ?? 0;

if (unitsInStock != null)
    availableUnits = unitsInStock;
else
    availableUnits = 0;

This is the null coalescing operator. It translates to: availableUnits equals unitsInStock unless unitsInStock equals null , in which case availableUnits equals 0.

It is used to change nullable types into value types.


The ?? operator returns the left-hand operand if it is not null, or else it returns the right operand.

?? Operator (C# Reference)

链接地址: http://www.djcxy.com/p/53834.html

上一篇: 这是一个if else语句吗?

下一篇: 什么? 在C#中是什么意思?