imported delegate patches from Daniel, new GetHashCode icalls
[mono.git] / mono / tests / delegate.cs
1 using System;
2 namespace Bah {
3 class Test {
4         delegate void SimpleDelegate ();
5         delegate string NotSimpleDelegate (int a);
6         
7         public int data;
8         
9         static void F () {
10                 Console.WriteLine ("Test.F from delegate");
11         }
12         public static string G (int a) {
13                 if (a != 2)
14                         throw new Exception ("Something went wrong in G");
15                 return "G got: " + a.ToString ();
16         }
17         public string H (int a) {
18                 if (a != 3)
19                         throw new Exception ("Something went wrong in H");
20                 return "H got: " + a.ToString () + " and " + data.ToString ();
21         }
22         public Test () {
23                 data = 5;
24         }
25         static int Main () {
26                 Test test = new Test ();
27                 SimpleDelegate d = new SimpleDelegate (F);
28                 NotSimpleDelegate d2 = new NotSimpleDelegate (G);
29                 NotSimpleDelegate d3 = new NotSimpleDelegate (test.H);
30                 d ();
31                 // we run G() and H() before and after using them as delegates
32                 // to be sure we don't corrupt them.
33                 G (2);
34                 test.H (3);
35                 Console.WriteLine (d2 (2));
36                 Console.WriteLine (d3 (3));
37                 G (2);
38                 test.H (3);
39
40                 if (d.Method.Name != "F")
41                         return 1;
42                 
43                 return 0;
44         }
45 }
46 }