2 using System.Runtime.InteropServices;
6 [DllImport("cygwin1.dll", EntryPoint="puts", CharSet=CharSet.Ansi)]
7 public static extern int puts (string name);
9 delegate void SimpleDelegate ();
10 delegate string NotSimpleDelegate (int a);
11 delegate int AnotherDelegate (string s);
16 Console.WriteLine ("Test.F from delegate");
18 public static string G (int a) {
20 throw new Exception ("Something went wrong in G");
21 return "G got: " + a.ToString ();
23 public string H (int a) {
25 throw new Exception ("Something went wrong in H");
26 return "H got: " + a.ToString () + " and " + data.ToString ();
32 Test test = new Test ();
33 SimpleDelegate d = new SimpleDelegate (F);
34 NotSimpleDelegate d2 = new NotSimpleDelegate (G);
35 NotSimpleDelegate d3 = new NotSimpleDelegate (test.H);
37 // we run G() and H() before and after using them as delegates
38 // to be sure we don't corrupt them.
41 Console.WriteLine (d2 (2));
42 Console.WriteLine (d3 (3));
46 if (d.Method.Name != "F")
49 if (d3.Method == null)
53 Console.WriteLine (d3.DynamicInvoke (args));
55 AnotherDelegate d4 = new AnotherDelegate (puts);
56 if (d4.Method == null)
59 Console.WriteLine (d4.Method);
60 Console.WriteLine (d4.Method.Name);
61 Console.WriteLine (d4.Method.DeclaringType);