我有一Item
堂课
public class Item {
//...
public DateTime CreateDate { get; set; }
public DateTime EndDate { get; set; }
}
在一种方法中,我有List<Item> items
. 如何比遍历列表更简洁地查询日期差异的平均值?
double days = 0;
int total = 0;
foreach (var @t in results)
{
if (@t.EndDate != null)
{
total++;
TimeSpan ts = (TimeSpan)(@t.EndDate - @t.CreateDate);
days = ts.TotalDays;
}
}
double avg = days / total;