我有两个时间跨度,我希望将第二个时间跨度添加到第一个时间段:
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。 为什么不在这种情况下添加工作?
答案 0 :(得分:6)
返回值为新TimeSpan
,原始TimeSpan
未修改。
试试这个:
weeklyWorkTimeHours = weeklyWorkTimeHours.Add(completeWorkTimeForCurrentDay.Value);