Skip to main content
 首页 » 编程设计

c#之hasvalue 运算符检查 null 有什么区别

2024年02月20日13yxwkf

<分区>

Possible Duplicate:
Which is preferred: Nullable<>.HasValue or Nullable<> == null?

我有字段 DateTime?日期

我需要检查日期是否为空并设置最小值。

var anyDate = Date ?? DateTime.MinValue(); 

或

var anyDate = Date.HasValue ? Date.Value : DateTime.MinValue(); 

什么是对的?