Faith_Spooky
Faith_Spooky

Reputation: 13

Count all items from timespan list into one timespan

Is there a way to count all the timespans from a list into one timespan.

Like:

List(00:15:00 + 00:15:00) = TimeSpan(00:30:00)

Upvotes: 1

Views: 72

Answers (1)

DavidG
DavidG

Reputation: 119017

You can use Linq Aggregate:

var timespans = new List<TimeSpan>
{
    new TimeSpan(0, 15, 0),
    new TimeSpan(0, 15, 0)
};

var totalTimespan = timespans.Aggregate((x, y) => x.Add(y));

Upvotes: 4

Related Questions