Sum of TimeSpans in C#

前端 未结 8 1002
执笔经年
执笔经年 2020-11-29 06:01

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

MyObject
{ 
    TimeSpan TheDuration { get; set; }
}

I want to use LINQ to

8条回答
  •  南方客
    南方客 (楼主)
    2020-11-29 06:59

    You can use .Aggregate rather than .Sum, and pass it a timespan-summing function that you write, like this:

        TimeSpan AddTimeSpans(TimeSpan a, TimeSpan b)
        {
            return a + b;
        }
    

提交回复
热议问题