มีบุคคลที่ผิดธรรมดาในคำอธิบายข้อยกเว้น: วัตถุที่ Nullable ต้องมีค่า (?!)
ปัญหานี้เป็นปัญหา:
ฉันมีDateTimeExtendedชั้นเรียนที่มี
{
DateTime? MyDataTime;
int? otherdata;
}
และผู้สร้าง
DateTimeExtended(DateTimeExtended myNewDT)
{
this.MyDateTime = myNewDT.MyDateTime.Value;
this.otherdata = myNewDT.otherdata;
}
ใช้รหัสนี้
DateTimeExtended res = new DateTimeExtended(oldDTE);
ขว้างInvalidOperationExceptionด้วยข้อความ:
วัตถุที่ Nullable ต้องมีค่า
myNewDT.MyDateTime.Value- ถูกต้องและมีDateTimeวัตถุปกติ
ข้อความนี้มีความหมายอะไรและฉันทำอะไรผิด
โปรดทราบว่าไม่oldDTE nullฉันได้ลบออกValueจากmyNewDT.MyDateTimeแต่ข้อยกเว้นเดียวกันถูกโยนเนื่องจาก setter ที่สร้างขึ้น