nullable object must have a value

前端 未结 8 1735
梦如初夏
梦如初夏 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;
    
    0 讨论(0)
  • 2020-11-30 00:51

    Try dropping the .value

    DateTimeExtended(DateTimeExtended myNewDT)
    {
       this.MyDateTime = myNewDT.MyDateTime;
       this.otherdata = myNewDT.otherdata;
    }
    
    0 讨论(0)
提交回复
热议问题