将时间跨度添加到另一个时间跨度不起作用
Add timespan to another timespan does not work
我有两个时间跨度,我想将第二个时间跨度添加到第一个时间跨度:
TimeSpan weeklyWorkTimeHours = new TimeSpan(0,0,0);
TimeSpan? completeWorkTimeForCurrentDay =
CalculateCompleteWorktime(currentWorkTimeItem).Value; /* I debugged through
the code. This method returns a correct timespan with a correct value */
weeklyWorkTimeHours.Add(completeWorkTimeForCurrentDay.Value);
但即使在最后一行代码之后,weeklyWorkTimeHours 仍包含 0,0,0。
为什么不在此上下文中添加工作?
return值是新的TimeSpan
,原TimeSpan
是未修改。
试试这个:
weeklyWorkTimeHours = weeklyWorkTimeHours.Add(completeWorkTimeForCurrentDay.Value);
我有两个时间跨度,我想将第二个时间跨度添加到第一个时间跨度:
TimeSpan weeklyWorkTimeHours = new TimeSpan(0,0,0);
TimeSpan? completeWorkTimeForCurrentDay =
CalculateCompleteWorktime(currentWorkTimeItem).Value; /* I debugged through
the code. This method returns a correct timespan with a correct value */
weeklyWorkTimeHours.Add(completeWorkTimeForCurrentDay.Value);
但即使在最后一行代码之后,weeklyWorkTimeHours 仍包含 0,0,0。 为什么不在此上下文中添加工作?
return值是新的TimeSpan
,原TimeSpan
是未修改。
试试这个:
weeklyWorkTimeHours = weeklyWorkTimeHours.Add(completeWorkTimeForCurrentDay.Value);