sum of timespans

Posted by frenchie on Stack Overflow See other posts from Stack Overflow or by frenchie
Published on 2011-01-16T00:33:32Z Indexed on 2011/01/16 0:53 UTC
Read the original article Hit count: 148

Filed under:
|
|

I have a collection of objects that include a timespan variable:

MyObject { TimeSpan TheDuration {get;set;} }

I want to use linq to sum those times. Of course, (from r in MyCollection select r.TheDuration).Sum(); doesn't work!

I'm thinking of changing the datatype of TheDuration to an int and then summing it and converting the sum to a TimeSpan. That'll be messy because each TheDuration in my collection is used in as a timespan somewhere else.

Any suggestion on this summation?

© Stack Overflow or respective owner

Related posts about c#

Related posts about ASP.NET