What does a double question mark do in C#?

Possible Duplicates:
?? Null Coalescing Operator --> What does coalescing mean?
What do two question marks together mean in C#?

I couldn't find this question being asked here so I figured I would ask it. What does a double question mark do in C#?

Example:

x = y ?? z;

This is a null coalescing operator. The method above states x is assigned y's value, unless y is null, in which case it is assigned z's value.


如果不是null,则使用y,否则使用z


From Wikipedia:

It's the null-coalesce operator and shorthand for this:

x = (y != null ? y : z);
链接地址: http://www.djcxy.com/p/9118.html

上一篇: 什么是默认(对象); 在C#中做?

下一篇: 双重问号在C#中做什么?