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 ();
29 public virtual void VF () {
30 Console.WriteLine ("Test.VF from delegate");
37 Test test = new Test ();
38 SimpleDelegate d = new SimpleDelegate (F);
39 SimpleDelegate d1 = new SimpleDelegate (test.VF);
40 NotSimpleDelegate d2 = new NotSimpleDelegate (G);
41 NotSimpleDelegate d3 = new NotSimpleDelegate (test.H);
44 // we run G() and H() before and after using them as delegates
45 // to be sure we don't corrupt them.
48 Console.WriteLine (d2 (2));
49 Console.WriteLine (d3 (3));
53 if (d.Method.Name != "F")
56 if (d3.Method == null)
60 Console.WriteLine (d3.DynamicInvoke (args));
62 AnotherDelegate d4 = new AnotherDelegate (puts);
63 if (d4.Method == null)
66 Console.WriteLine (d4.Method);
67 Console.WriteLine (d4.Method.Name);
68 Console.WriteLine (d4.Method.DeclaringType);