C# Nullable to string

后端 未结 11 1873
挽巷
挽巷 2020-12-16 09:29

I have a DateTime? variable, sometimes the value is null, how can I return an empty string \"\" when the value is null or

11条回答
  •  既然无缘
    2020-12-16 10:07

    Though many of these answers are correct, all of them are needlessly complex. The result of calling ToString on a nullable DateTime is already an empty string if the value is logically null. Just call ToString on your value; it will do exactly what you want.

提交回复
热议问题