5
如果我有一个方法:编译器如何理解Nullables?
protected int CalculateActualDuration(DateTime? startDate, DateTime? endDate) {
if (startDate.HasValue && endDate.HasValue) {
return Math.Abs((int)(endDate.Value.Subtract(startDate.Value).TotalMinutes));
}
else {
return 0;
}
}
我能够通过传递两个日期时间要调用的方法?和一个DateTime。那么编译器如何理解这种差异呢?
这是否意味着,如果我通过在datetime值,像
if (true && true)
和所有的*。价值已被更改为正确的对象if语句基本上将soemthing?那么所有endDate.Value都是现在的EndDates?
在运行时,编译器是否将所有不为空的参数都转换为空字符串?
最后一个问题的答案是“是”。把一个可以为空的DateTime看作一个正常的DateTime,并粘贴一个布尔值来指示它的无效性。现在是否清楚编译器如何处理将正常的DateTime转换为可为空的DateTime? – 2015-02-09 03:43:33