You're calling Add
, but not using the result at all. Add
doesn't change the value - it returns a new value. You want:
TotalWorkHours = TotalWorkHours.Add(Interval[i]);
Or more idiomatically, IMO:
TotalWorkHours += Interval[i];
Or even more idiomatically, to my mind:
// Note the casing of the variable names to follow conventions,
// and the fact that "intervals" is plural because it contains
// more than one interval.
List<TimeSpan> intervals = ...;
var totalWorkHours = TimeSpan.Zero;
foreach (var interval in intervals)
{
totalWorkHours += interval;
}
Or even just use LINQ aggregation:
var totalWorkHours = intervals.Aggregate(TimeSpan.Zero, (x, y) => x + y);