'ToString()' takes 1 arguments when DateTime?(Nullable) type I uses [duplicate]

对着背影说爱祢 提交于 2019-12-12 01:45:31

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!