必须有一个简单的答案:
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).
时间跨度是值类型。 尝试:
TimeSpans are value types. Try:
totalTime = totalTime.Add(时间)