--- /dev/null
+//
+// Parameter and return value compilation tests for anonymous methods
+//
+delegate void D (int x);
+delegate void E (out int x);
+
+class X {
+ static int Main ()
+ {
+ // This should create an AnonymousMethod with the implicit argument
+ D d1 = delegate {};
+ D d2 = delegate (int a) {};
+
+ return 0;
+ }
+}
--- /dev/null
+delegate void S ();
+
+class X {
+
+ //
+ // DO NOT ADD ANYTHING ELSE TO THIS TEST
+ //
+ static int Main ()
+ {
+ int a;
+
+ S b = delegate {
+ a = 2;
+ };
+
+ return 0;
+ }
+}
--- /dev/null
+delegate void S ();
+using System;
+
+class X {
+ static int Main ()
+ {
+ int a = 1;
+ Console.WriteLine ("A is = " + a);
+ int c = a;
+ Console.WriteLine (c);
+ if (a != 1){
+ return 1;
+ }
+
+ S b = delegate {
+ if (a != 1)
+ Environment.Exit (1);
+ Console.WriteLine ("in Delegate");
+ a = 2;
+ if (a != 2)
+ Environment.Exit (2);
+ Console.WriteLine ("Inside = " + a);
+ a = 3;
+ Console.WriteLine ("After = " + a);
+ };
+ if (a != 1)
+ return 3;
+ b ();
+ if (a != 3)
+ return 4;
+ Console.WriteLine ("Back, got " + a);
+
+ return 0;
+ }
+}
--- /dev/null
+delegate void S ();
+using System;
+
+class X {
+ static void Main ()
+ {
+ int a = 1;
+ S b = delegate {
+ a = 2;
+ };
+ b ();
+ Console.WriteLine ("Back, got " + a);
+ }
+}
--- /dev/null
+delegate void S ();
+using System;
+
+class X {
+ static void Main ()
+ {
+ int a = 1;
+ S b = delegate {
+ float f = 1;
+ Console.WriteLine (a);
+ if (f == 2)
+ return;
+ };
+ b ();
+ Console.WriteLine ("Back, got " + a);
+ }
+}
--- /dev/null
+//
+// Tests capturing of double nested variables
+//
+delegate void S ();
+using System;
+
+class X {
+ static int Main ()
+ {
+ int i;
+ S b = null;
+
+ for (i = 0; i < 10; i++){
+ int j = 0;
+ b = delegate {
+ Console.WriteLine ("i={0} j={1}", i, j);
+ i = i + 1;
+ j = j + 1;
+ };
+ }
+ b ();
+ Console.WriteLine ("i = {0}", i);
+ if (!t (i, 11))
+ return 1;
+ b ();
+ if (!t (i, 12))
+ return 2;
+ Console.WriteLine ("i = {0}", i);
+ return 0;
+ }
+
+ static bool t (int a, int b)
+ {
+ return a == b;
+ }
+}
--- /dev/null
+//
+// Tests capturing of variables
+//
+delegate void S ();
+using System;
+
+class X {
+ static int Main ()
+ {
+ int a = 1;
+ if (a != 1)
+ return 1;
+
+ Console.WriteLine ("A is = " + a);
+ S b= delegate {
+ Console.WriteLine ("on delegate");
+ a = 2;
+ };
+ if (a != 1)
+ return 2;
+ b();
+ if (a != 2)
+ return 3;
+ Console.WriteLine ("OK");
+ return 0;
+ }
+}
+
--- /dev/null
+//
+// Tests havign more than one anonymous method that captures the same variable
+//
+using System;
+
+delegate void D ();
+
+class X {
+ static int Main ()
+ {
+ int a = 0;
+ D d1 = delegate {
+ Console.WriteLine ("First");
+ a = 1;
+ };
+
+ D d2 = delegate {
+ Console.WriteLine ("Second");
+ a = 2;
+ };
+ if (!t (a, 0))
+ return 1;
+ d1 ();
+ if (!t (a, 1))
+ return 2;
+ d2 ();
+ if (!t (a, 2))
+ return 3;
+ Console.WriteLine ("Test passes OK");
+ return 0;
+ }
+
+ static bool t (int a, int b)
+ {
+ return a == b;
+ }
+}
--- /dev/null
+//
+// Tests capturing of double nested variables
+//
+delegate void S ();
+using System;
+
+class X {
+ static int Main ()
+ {
+ int i;
+ int a = 0;
+ S b = null;
+
+ for (i = 0; i < 10; i++){
+ int j = 0;
+ b = delegate {
+ Console.WriteLine ("i={0} j={1}", i, j);
+ i = i + 1;
+ j = j + 1;
+ a = j;
+ };
+ }
+ b ();
+ Console.WriteLine ("i = {0}", i);
+ if (!t (i, 11))
+ return 1;
+ b ();
+ if (!t (i, 12))
+ return 2;
+ Console.WriteLine ("i = {0}", i);
+ Console.WriteLine ("a = {0}", a);
+ if (!t (a, 2))
+ return 3;
+
+ return 0;
+ }
+
+ static bool t (int a, int b)
+ {
+ return a == b;
+ }
+}