Merge pull request #4935 from lambdageek/dev-handles-may
[mono.git] / mcs / tests / test-anon-21.cs
1 //
2 // Nested anonymous methods and capturing of variables test
3 //
4 using System;
5
6 delegate void D ();
7
8 class X {
9
10         public static int Main ()
11         {
12                 X x = new X();
13                 x.M ();
14                 e ();
15                 Console.WriteLine ("J should be 101= {0}", j);
16                 if (j != 101)
17                         return 3;
18                 Console.WriteLine ("OK");
19                 return 0;
20         }
21
22         static int j = 0;
23         static D e;
24         
25         void M ()
26         {
27                 int l = 100;
28
29                 D d = delegate {
30                         int b;
31                         b = 1;
32                         Console.WriteLine ("Inside d");
33                         e = delegate {
34                                         Console.WriteLine ("Inside e");
35                                         j = l + b;
36                                         Console.WriteLine ("j={0} l={1} b={2}", j, l, b);
37                         };
38                 };
39                 Console.WriteLine ("Calling d");
40                 d ();
41         }
42         
43 }