Ejemplo n.º 1
0
        public static decimal?Sum(this IIterable <decimal?> source)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            decimal sum = 0;

            source.ForEach(
                o => sum = sum + o ?? 0
                );

            return(sum);
        }
Ejemplo n.º 2
0
        public static long?Sum(this IIterable <long?> source)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            long sum = 0;

            source.ForEach(
                o => sum = checked (sum + o ?? 0)
                );

            return(sum);
        }
Ejemplo n.º 3
0
        public static int Sum(this IIterable <int> source)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            int sum = 0;

            source.ForEach(
                o => sum = checked (sum + o)
                );

            return(sum);
        }
Ejemplo n.º 4
0
        public static double Sum(this IIterable <double> source)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            double sum = 0;

            source.ForEach(
                o => sum = sum + o
                );

            return(sum);
        }
Ejemplo n.º 5
0
        public static TNewResult Aggregate <TSource, TAccumulate, TNewResult>(this IIterable <TSource> source, TAccumulate seed, Func <TAccumulate, TSource, TAccumulate> func, Func <TAccumulate, TNewResult> resultSelector)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            if (func == null)
            {
                throw new ArgumentNullException("func");
            }
            if (resultSelector == null)
            {
                throw new ArgumentNullException("resultSelector");
            }

            source.ForEach(
                o => seed = func(seed, o)
                );

            return(resultSelector(seed));
        }