views:

45

answers:

3

There has to be an easy answer:

            var totalTime = TimeSpan.Zero;

            foreach (var timesheet in timeSheets)
            {
               //assume "time" is a correct, positive TimeSpan
                var time = timesheet.EndTime - timesheet.StartTime;
                totalTime.Add(time);
            }

There's only one value in the list timeSheets and it is a positive TimeSpan (verified on local inspection).

+3  A: 

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

Bradley Smith
+3  A: 

TimeSpans are value types. Try:

totalTime = totalTime.Add(time)

Jamezor
A: 

totalTime = totalTime.Add(time)

Jason Coyne