public static DateTime ResolveDate()
{
return null;
}
我需要从返回 DateTime
类型的函数返回一个 null
值。我的主要目标是不使用 MinValue或返回一个 new Datetime();
[返回默认日期] 并且前端将日期显示为空值(空白)-> ""
最佳答案
public static DateTime? ResolveDate()
{
if ( someconditon = true )
{
return DateTime.Now
}
else
{
return null;
}
}
另一种方法是使用类似 TryParse 的东西
Public static bool TryResolve (out Resolvedate)
{
if ( someconditon = true )
{
Resolvedate = DateTime.Now
return true;
}
else
{
return false;
}
}
关于c# - 从返回 DateTime 的 Function 返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8601774/