且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在日期和时间中允许空值

更新时间:2023-02-09 14:36:11

如下所示初始化您的DateTime属性

Initialize Your DateTime property like below
public DateTime? Date{get;set;}





希望这有帮助



Hope this helps


最简单的选择是使用可空类型 [ ^ ]。

Eg 的DateTime? dt = null;



这里 [ ^ ]就是一个很好的例子。



但是,您需要确保在显示之前将此值检查为null。
The easiest option would be to use a nullable type[^].
E.g. DateTime? dt = null;

Here[^] is a good example.

However, you will need to make sure you check this value for null before display.


C#支持可以约会的日期时间 [ ^ ]

C# does support Nullable DateTime[^]
DateTime? MyNullableDate = null;



是一个有效的声明。


is a valid statement.