无法确定条件表达式的类型,因为“DateTime”和“<null>”之间没有隐式转换|Nullable类型问题与?:条件运算符

Nullable类型问题与?:条件运算符

1.方式1

x.UpdateTime.HasValue ? x.UpdateTime.Value : (DateTime?)null

2.方式2

DateTime? uDT = null;
x.UpdateTime.HasValue ? x.UpdateTime.Value : uDT

3.方式3

DateTime? updateTime;
if (x.UpdateTime.HasValue)
    updateTime = x.UpdateTime.Value;
else
    updateTime = null;
原文地址:https://www.cnblogs.com/ChenRihe/p/8806927.html