我想在 C# 中为 DateTime 变量传递空值。该值应作为空值存储在数据库中。
我试过使用 Datetime.Minvalue,但它存储了一个默认值。它在数据库中必须为空。我该怎么做?
最佳答案
使用 DateTime?
作为
DateTime? foo = null;
这使得 nullable 日期时间
:
A nullable type can represent the normal range of values for its underlying value type, plus an additional null value.
然后在写出这个值的时候,你可以这样使用这个值:
if(foo == null)
{
// Handle the null case
}
else
{
// Handle the non-null case
}
关于c# - 日期时间变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/641267/