nullable object must have a value

前端 未结 8 1741
梦如初夏
梦如初夏 2020-11-30 00:17

There is paradox in the exception description: Nullable object must have a value (?!)

This is the problem:

I have a DateTimeExtended class, tha

8条回答
  •  借酒劲吻你
    2020-11-30 00:45

    In this case oldDTE is null, so when you try to access oldDTE.Value the InvalidOperationException is thrown since there is no value. In your example you can simply do:

    this.MyDateTime = newDT.MyDateTime;
    

提交回复
热议问题