本文介绍了加入时间跨度到另一个时间跨度不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个时间跨度,我想第二个时间跨度添加到第一个时间跨度:

I have two timespans and I want to add the second timespan to the first timespan:

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);

不过,即使是code中的最后一行后,weeklyWorkTimeHours包含0,0,0。为什么没有在这方面增加的工作?

But even after the last line of code, weeklyWorkTimeHours contains 0,0,0.Why doesn't add work in this context?

推荐答案

返回值是一个新的时间跨度,原时间跨度不修改

The return value is a new TimeSpan, the original TimeSpan is not modified.

试试这个:

weeklyWorkTimeHours = weeklyWorkTimeHours.Add(completeWorkTimeForCurrentDay.Value);

这篇关于加入时间跨度到另一个时间跨度不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 13:16