日期时间可以为空吗? [英] Can a DateTime be null?

查看:155
本文介绍了日期时间可以为空吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

DateTime空值

是否可以将datetime对象设置为null?

is it possible to set datetime object to null?

推荐答案

DateTime 值类型,就像 int double ,没有有意义的 null 值。

DateTime is a value type, which, just like int and double, has no meaningful null value.

在VB.NET中,您可以这样写:

In VB.NET, you can write this:

Dim d As DateTime = Nothing

但这只是将 d 设置为默认值 DateTime 值。在C#中,等效代码如下:

But all this does is to set d to the default DateTime value. In C# the equivalent code would be this:

DateTime d = default(DateTime);

...相当于 DateTime.MinValue

也就是说,有 Nullable< T> 类型,用于为 null 提供值任何值类型 T 。 C#中 Nullable< DateTime> 的简写是 DateTime?

That said, there is the Nullable<T> type, which is used to provide a null value for any value type T. The shorthand for Nullable<DateTime> in C# is DateTime?.

这篇关于日期时间可以为空吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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