[w32file] Move MonoIO.Find{First,Next,Close} to managed
[mono.git] / mcs / tests / gtest-lambda-15.cs
1 using System;
2 using System.Collections.Generic;
3
4 static class Enumerable
5 {
6
7         public static int Sum<TSource> (this IEnumerable<TSource> source, Func<TSource, int> selector)
8         {
9                 return Sum<TSource, int> (source, (a, b) => a + selector (b));
10         }
11
12         static TR Sum<TA, TR> (this IEnumerable<TA> source, Func<TR, TA, TR> selector)
13         {
14                 if (source == null)
15                         throw new ArgumentNullException ("source");
16                 if (selector == null)
17                         throw new ArgumentNullException ("selector");
18
19                 TR total = default (TR);
20                 int counter = 0;
21                 foreach (var element in source) {
22                         total = selector (total, element);
23                         ++counter;
24                 }
25
26                 if (counter == 0)
27                         throw new InvalidOperationException ();
28
29                 return total;
30         }
31
32 }
33
34 class Repro
35 {
36
37         public static int Main ()
38         {
39                 var sum = new [] { "1", "2", "3", "4", "5", "6", "7" }.Sum ((s) => int.Parse (s));
40                 if (sum != 28)
41                         return 4;
42
43                 Console.WriteLine (sum);
44                 return 0;
45         }
46 }