我在课堂上定义了这个
public DateTime? LineCheckSubmitDateTime { set; get; }
我需要使用我的初始化这个变量gridview
但有时我需要将此值保留为空,但是当我离开时它会返回1 / 1 / 0001 12:00:00 AM
所以这是我的代码:
newObj.LineCheckSubmitDateTime = (Convert.ToDateTime(gridViewDetails.GetRowCellValue(rowHandle, "LineCheckSubmitDateTime"))==DateTime.Parse("1 / 1 / 0001 12:00:00 AM") ) ? Convert.ToDateTime(gridViewDetails.GetRowCellValue(rowHandle, "LineCheckSubmitDateTime")):null;
所以两个问题:
1:此代码返回此错误:
Severity Code Description Project File Line
Error CS0173 Type of conditional expression cannot be determined because there is no implicit conversion between 'DateTime' and '<null>'
2:你有更好的解决方案吗?