【发布时间】:2011-02-02 12:48:35
【问题描述】:
你认为 C# 会支持 ??= 运算符之类的东西吗?
而不是这个:
if (list == null)
list = new List<int>();
或许可以这样写:
list ??= new List<int>();
现在,我可以使用(但在我看来不太可读):
list = list ?? new List<int>();
【问题讨论】:
-
那太酷了!不确定它是否支持它......但是是的,我喜欢它!
-
这个想法建议让我的 Ruby 部分感到温暖。 (请参阅 Ruby
||=运算符。)
标签: c# operators null-coalescing-operator null-coalescing