Long Sum IEnumerable - CSharp System.Collections.Generic

CSharp examples for System.Collections.Generic:IEnumerable

Description

Long Sum IEnumerable

Demo Code


using System.Linq;
using System.Collections.Generic;
using System;/*from   w w w  .  j  av a 2s. co m*/

public class Main{
        public static long LongSum(this IEnumerable<int> collection)
        {
            long sum = 0;
            foreach (var i in collection)
                sum += i;

            return sum;
        }
        public static long LongSum<T>(this IEnumerable<T> collection, Func<T, int> selector)
        {
            long sum = 0;
            foreach (var i in collection)
                sum += selector(i);

            return sum;
        }
}

Related Tutorials