Ejemplo n.º 1
0
    public static decimal Product <T>(this IEnumerable <T> en, CustomTypeNumericalValue <T> numericalVal)
    {
        decimal product = 1;

        foreach (T element in en)
        {
            dynamic e = element;
            product = product * numericalVal(element);
        }
        return(product);
    }
Ejemplo n.º 2
0
    //this version is for user defined types (classes structures etc)
    public static decimal Sum <T>(this IEnumerable <T> en, CustomTypeNumericalValue <T> numericalVal)
    {
        decimal sum = 0;

        foreach (T element in en)
        {
            dynamic e = element;
            sum = sum + numericalVal(element);
        }
        return(sum);
    }
Ejemplo n.º 3
0
    public static decimal Average <T>(this IEnumerable <T> en, CustomTypeNumericalValue <T> numericalVal)
    {
        decimal sum   = 0;
        int     count = 0;

        foreach (T element in en)
        {
            dynamic e = element;
            sum = sum + numericalVal(element);
            count++;
        }
        return(sum / count);
    }
Ejemplo n.º 4
0
        public static decimal Product <T>(this IEnumerable <T> collection, CustomTypeNumericalValue <T> numericalVal)
        {
            if (collection == null)
            {
                throw new ArgumentNullException("empty collection");
            }
            decimal sum = 1;

            foreach (T element in collection)
            {
                sum = sum * numericalVal(element);
            }
            return(sum);
        }
Ejemplo n.º 5
0
        public static decimal Average <T>(this IEnumerable <T> collection, CustomTypeNumericalValue <T> numericalVal)
        {
            if (collection == null)
            {
                throw new ArgumentNullException("empty collection");
            }
            decimal sum   = 0;
            long    count = 0;

            foreach (T element in collection)
            {
                sum = sum + numericalVal(element);
                count++;
            }

            if (count == 0)
            {
                throw new ArgumentOutOfRangeException("Collection contains no elements");
            }
            else
            {
                return(sum / count);
            }
        }