Add timespan to another timespan does not work [duplicate]

↘锁芯ラ 提交于 2019-12-04 06:24:21

问题


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

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


回答1:


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

Try this:

weeklyWorkTimeHours = weeklyWorkTimeHours.Add(completeWorkTimeForCurrentDay.Value);


来源:https://stackoverflow.com/questions/28041852/add-timespan-to-another-timespan-does-not-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!