因为我有
public class Foo
{
public int? Id { get; set; }
}
什么更好
if ((Id ?? 0) == 0) {}
或
if (Id == null || Id == 0)
?
最佳答案
我推荐第二个。它更具可读性。
正如我所注意到的,很少有人熟悉 ??
运算符。
关于c# - 什么更好 : id ? ? 0 == 0 或 id == null ||编号 == 0?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4956927/