Why isn't my TimeSpan.Add() working?

后端 未结 3 1409
后悔当初
后悔当初 2020-12-10 00:50

There has to be an easy answer:

var totalTime = TimeSpan.Zero;

foreach (var timesheet in timeSheets)
{
   //assume \"time\" is a correct, positive TimeSpan
         


        
相关标签:
3条回答
  • 2020-12-10 01:34
    totalTime = totalTime.Add(time)
    
    0 讨论(0)
  • 2020-12-10 01:35

    TimeSpans are value types. Try:

    totalTime = totalTime.Add(time)

    0 讨论(0)
  • 2020-12-10 01:50

    This is a common mistake. TimeSpan.Add returns a new instance of TimeSpan.

    0 讨论(0)
提交回复
热议问题