c# - 什么更好 : id ? ? 0 == 0 或 id == null ||编号 == 0?

标签 c# performance c#-4.0

因为我有

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/

相关文章:

c# - 我如何解决 Cannot create a DbSet for 'CUserMasterLocal' because this type is not included in the model for the context

c# - 如果元素计数小于 'n',则删除数组中的所有相似元素

c# - 使用 C# 连接并读取 .MDB 项目

c++ - C++中的指针与变速

c#-4.0 - Windows Azure 模拟器 "Invalid access to memory location."

c# - 无法访问原始 key 文件的 .NET 程序集的 StrongName

php - 如何提高分页速度

CSS剪辑使用GPU?

C# WebApi 传入客户端证书始终为空

c# - WCF 4.0 - 从 URL 或 POST 主体获取参数