DataTime? 的 GetValueOrDefault() 方法

时间:2022-07-20 14:50:17

DataTime? 转换为 DataTime类型 就可以调用 ToString()  自定义格式

@item.CreateDate.GetValueOrDefault().ToString("yyyy-MM-dd");

// 摘要:
// 获取一个值,指示当前的 System.Nullable<T> 对象是否有值。
//
// 返回结果:
// 如果当前的 System.Nullable<T> 对象具有值,则为 true;如果当前的 System.Nullable<T> 对象没有值,则为
// false。
public bool HasValue { get; }

//
// 摘要:
// 检索当前 System.Nullable<T> 对象的值,或该对象的默认值。
//
// 返回结果:
// 如果 System.Nullable<T>.HasValue 属性为 true,则为 System.Nullable<T>.Value 属性的值;否则为当前
// System.Nullable<T> 对象的默认值。默认值的类型为当前 System.Nullable<T> 对象的类型参数,而默认值的值中只包含二进制零。
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
public T GetValueOrDefault();