?? 运算符

?? 运算符定义在将可以为 null 的类型分配给非可以为 null 的类型时返回的默认值。

int? c = null;

// d = c, unless c is null, in which case d = -1.
int d = c ?? -1;

此运算符还可用于多个可以为 null 的类型。例如:

int? e = null;
int? f = null;

// g = e or f, unless e and f are both null, in which case g = -1.
int g = e ?? f ?? -1;

posted @ 2013-10-22 17:25  nygfcn  阅读(201)  评论(0编辑  收藏  举报