Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
111 views
Welcome To Ask or Share your Answers For Others

1 Answer

TimeSpans are value types. Try:

totalTime = totalTime.Add(time)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...