.net – Nullable类型,如果问题
发布时间:2020-12-17 07:25:36 所属栏目:百科 来源:网络整理
导读:这是最简单的代码 Dim testInvoiceDate As DateTime? = If(String.IsNullOrEmpty(Nothing),Nothing,New DateTime(2018,3,20)) 为什么变量testInvoiceDate不是Nothing,而是#1/1 / 0001 12:00:00 AM#?! 这很奇怪! 解决方法 If语句将为两种情况返回相同的数据
这是最简单的代码
Dim testInvoiceDate As DateTime? = If(String.IsNullOrEmpty(Nothing),Nothing,New DateTime(2018,3,20)) 为什么变量testInvoiceDate不是Nothing,而是#1/1 / 0001 12:00:00 AM#?! 解决方法
If语句将为两种情况返回相同的数据类型.
因为False-case中的return-type是DateTime,所以return-type是True-case的DateTime-default-value. DateTime的默认值是DateTime.MinValue,即#1/1/0001 12:00:00 AM#. 这将按预期工作: Dim testInvoiceDate As DateTime? = If(String.IsNullOrEmpty(Nothing),New DateTime?(New Date(2018,20))) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 缺少依赖项在Windows 7上安装NumPy 1.9 for Python 3.4.1 3
- 解决vue项目打包后提示图片文件路径错误的问题
- 史上最全最常用的正则表达式
- c# – SSRS:在单个Web服务调用中获取所有报告和参数的列表
- grep命令与正则表达式(过滤)一
- ios – Cocoapods完全破产
- AJAX学习之序列二:struts2 jquery json 实现AJAX 注册ID验
- 未能加载文件或程序集“Newtonsoft.Json, Version=4.5.0.0,
- c# – 如何在Windows应用商店应用中的ListView / GridView中
- 在C中寻找优化算法来替换Excel求解器