CSharp examples for System.Collections.Generic:IEnumerable
Long Sum IEnumerable
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; } }