-//\r
-// Tests different anonymous method caching scenarios\r
-//\r
-\r
-public delegate void StringSender (string str);\r
-public delegate void VoidDelegate ();\r
-\r
-public class MainClass\r
-{\r
- public static void Main()\r
- {\r
- MainClass mc = new MainClass ();\r
- VoidDelegate del = new VoidDelegate (\r
- delegate {\r
- StringSender ss = delegate (string s) {\r
- SimpleCallback(mc, s);\r
- };\r
- ss("Yo!");\r
- }\r
- );\r
- del();\r
- \r
- mc.Test2 (10);\r
- mc.Test3 (20);\r
- mc.Test4 ();\r
- mc.Test5 (50);\r
- }\r
- \r
- void Test2 (int a)\r
- {\r
- StringSender d = delegate (string s) {\r
- VoidDelegate d2 = delegate {\r
- s = "10";\r
- };\r
- };\r
- }\r
- \r
- void Test3 (int a)\r
- {\r
- int u = 8;\r
- VoidDelegate d = delegate () { u = 9; };\r
- VoidDelegate d2 = delegate () { };\r
- }\r
-\r
- void Test4 ()\r
- {\r
- VoidDelegate d = delegate () {\r
- VoidDelegate d2 = delegate () {\r
- int a = 9;\r
- VoidDelegate d3 = delegate () {\r
- VoidDelegate d4 = delegate () {\r
- a = 3;\r
- };\r
- };\r
- };\r
- };\r
- }\r
- \r
- int a;\r
- int b;\r
- \r
- delegate int D (int a);\r
- \r
- void Test5 (int arg)\r
- {\r
- D d2 = delegate (int i) {\r
- D d1 = delegate (int a) {\r
- return a;\r
- };\r
-\r
- return d1 (9) + arg;\r
- };\r
- }\r
- \r
- static void SimpleCallback (MainClass mc, string str)\r
- {\r
- System.Console.WriteLine(str);\r
- }\r
-}\r
+//
+// Tests different anonymous method caching scenarios
+//
+
+public delegate void StringSender (string str);
+public delegate void VoidDelegate ();
+
+public class MainClass
+{
+ public static void Main()
+ {
+ MainClass mc = new MainClass ();
+ VoidDelegate del = new VoidDelegate (
+ delegate {
+ StringSender ss = delegate (string s) {
+ SimpleCallback(mc, s);
+ };
+ ss("Yo!");
+ }
+ );
+ del();
+
+ mc.Test2 (10);
+ mc.Test3 (20);
+ mc.Test4 ();
+ mc.Test5 (50);
+ }
+
+ void Test2 (int a)
+ {
+ StringSender d = delegate (string s) {
+ VoidDelegate d2 = delegate {
+ s = "10";
+ };
+ };
+ }
+
+ void Test3 (int a)
+ {
+ int u = 8;
+ VoidDelegate d = delegate () { u = 9; };
+ VoidDelegate d2 = delegate () { };
+ }
+
+ void Test4 ()
+ {
+ VoidDelegate d = delegate () {
+ VoidDelegate d2 = delegate () {
+ int a = 9;
+ VoidDelegate d3 = delegate () {
+ VoidDelegate d4 = delegate () {
+ a = 3;
+ };
+ };
+ };
+ };
+ }
+
+ int a;
+ int b;
+
+ delegate int D (int a);
+
+ void Test5 (int arg)
+ {
+ D d2 = delegate (int i) {
+ D d1 = delegate (int a) {
+ return a;
+ };
+
+ return d1 (9) + arg;
+ };
+ }
+
+ static void SimpleCallback (MainClass mc, string str)
+ {
+ System.Console.WriteLine(str);
+ }
+}