generic ?
2
, + / - / * / etc ...
, , . .
, , , +
T
. , lambda
public static T SUM<T>(IEnumerable<T> dataCollection, Func<T, T, T> sum)
{
T total = default(T);
foreach(var value in dataCollection)
total = sum(total, value);
return total;
}
List<int> list = ...;
list.Sum((left, right) -> left + right);
. , , , System.Linq.Enumerable.Aggregate
. , , , .
+6