[英]Null-coalescing operator ?? vs. ??= in C#
Is use of??是用的?? when checking a null using null-coalescing operator and there is??= in C# 8.0.当使用空合并运算符检查 null 并且 C# 8.0 中有 ??= 时。 There is the same functionality behavior and what is the advantage of using ==?有相同的功能行为,使用 == 有什么好处? operator.操作员。
int? a = null;
int b = 10;
a = a ??= 0;
a = a ?? b;
What is "bad practice" is highly opinionated, but in this case, not really.什么是“不好的做法”是自以为是的,但在这种情况下,并非如此。
The new operator ??=
only replaces the common case of a = a?? b
新的运算符??=
只替换了a = a?? b
的常见情况。 a = a?? b
. a = a?? b
。
There are still many other users for ??
还有很多其他用户??
, eg if (a?.Foo()?? false)
or Foo(a?? 0)
or var c = a?? b
,例如if (a?.Foo()?? false)
或Foo(a?? 0)
或var c = a?? b
var c = a?? b
etc. var c = a?? b
等
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.