什么是" ??"运营商? [英] What is the "??" operator for?

查看:194
本文介绍了什么是" ??"运营商?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道 ??在 C# 迹象code。这是什么呢?我如何使用它?

什么 INT??它是一个可空INT?

参见:


  

<一个href=\"http://stackoverflow.com/questions/770186/null-coalescing-operator-what-does-coalescing-mean\">??空合并运算符 - >是什么意思凝聚



解决方案

这就是所谓的空合并运算符和作品是这样的:

而不是做的:

 诠释?数=无效;
INT结果=号== NULL? 0:数;

您可以现在只是做:

  INT结果= ??号0;

I was wondering about ?? signs in C# code. What is it for? And how can I use it?

What about int?? Is it a nullable int?

See also:

?? Null Coalescing Operator —> What does coalescing mean?

解决方案

It's called the "null coalescing operator" and works something like this:

Instead of doing:

int? number = null;
int result = number == null ? 0 : number;

You can now just do:

int result = number ?? 0;

这篇关于什么是&QUOT; ??&QUOT;运营商?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆