public static decimal Product <T>(this IEnumerable <T> en, CustomNumberType <T> numValue) { decimal product = 1; foreach (T element in en) { dynamic e = element; product *= numValue(element); } return(product); }
//this versions are for user defined types (classes structures etc) public static decimal Sum <T>(this IEnumerable <T> en, CustomNumberType <T> numValue) { decimal sum = 0; foreach (T element in en) { dynamic e = element; sum += numValue(element); } return(sum); }
public static decimal Average <T>(this IEnumerable <T> en, CustomNumberType <T> numValue) { decimal sum = 0; int count = 0; foreach (T element in en) { dynamic e = element; sum += numValue(element); count++; } return(sum / count); }