C#可空<&日期时间GT;字符串 [英] C# Nullable<DateTime> to string

查看:77
本文介绍了C#可空<&日期时间GT;字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个的DateTime?变量,有时值为,我怎么能返回一个空字符串当值的DateTime 价值时,没有


解决方案

 字符串日期= myVariable.HasValue? myVariable.Value.ToString()的String.Empty;  


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

解决方案

string date = myVariable.HasValue ? myVariable.Value.ToString() : string.Empty;

这篇关于C#可空<&日期时间GT;字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆