问题
DateTime? NullableWhen I use DateTime? as Nullable type "ToString("dd MMMMyyyy " + "(HH:mm tt)")" error appears.
回答1:
You must use something like this. I've added null check as suggested by Colin
if(dateVariable.HasValue)
string dateString = dateVariable.Value.ToString("dd MMMMyyyy " + "(HH:mm tt)");
Nullable<T>
is a generc and it wraps object. You must access it via .Value
property.
来源:https://stackoverflow.com/questions/39328689/tostring-takes-1-arguments-when-datetimenullable-type-i-uses