I wanted to assign null value to DateTime type in c#, so I used:
public DateTime? LockTime;
When LockTime is not assigned LockTime.Value contains null by default.
I want to be able to change LockTime.Value to null after it has been assigned other value.
No, if
LockTimehasn’t been assigned a value, it will be the nullable value by default – soLockTime.Valuewill throw an exception if you try to access it.You can’t assign null to
LockTime.Valueitself, firstly because it’s read-only and secondly because the type ofLockTime.Valueis the non-nullableDateTimetype.However, you can set the value of the variable to be the null value in several different ways: