2010-04-13 Sebastien Pouliot <sebastien@ximian.com>
[mono-project.git] / mcs / tests / test-26.cs
blob38b173ca3bd001a6e5715ddfe144e97e65350c86
1 using System;
3 public class Blah {
5 public delegate int MyDelegate (int i, int j);
7 public int Foo (int i, int j)
9 return i+j;
12 public static int Test1 ()
14 Blah f = new Blah ();
16 MyDelegate del = new MyDelegate (f.Foo);
18 MyDelegate another = new MyDelegate (del);
20 int number = del (2, 3);
22 int i = another (4, 6);
24 Console.WriteLine ("Delegate invocation of one returned : " + number);
26 Console.WriteLine ("Delegate invocation of the other returned : " + i);
28 if (number == 5 && i == 10)
29 return 0;
30 else
31 return 1;
34 public delegate int List (params int [] args);
36 public static int Adder (params int [] args)
38 int total = 0;
40 foreach (int i in args)
41 total += i;
43 return total;
46 public static int Test2 ()
48 List my_adder = new List (Adder);
50 if (my_adder (1, 2, 3) != 6)
51 return 2;
53 return 0;
56 public static int Main ()
58 int v;
60 v = Test1 ();
61 if (v != 0)
62 return v;
64 v = Test2 ();
65 if (v != 0)
66 return v;
68 Console.WriteLine ("All tests pass");
69 return 0;