Merge pull request #495 from nicolas-raoul/fix-for-issue2907-with-no-formatting-changes
[mono.git] / mcs / tests / test-anon-02.cs
1 //
2 // This test checks various uses of captured local variables
3 //
4 using System;
5
6 delegate void S ();
7
8 class X {
9         public static int Main ()
10         {
11                 int a = 1;
12                 Console.WriteLine ("A is = " + a);
13                 int c = a;
14                 Console.WriteLine (c);
15                 if (a != 1){
16                         return 1;
17                 }
18                 
19                 S b = delegate {
20                         if (a != 1)
21                                 Environment.Exit (1);
22                         Console.WriteLine ("in Delegate");
23                         a = 2;
24                         if (a != 2)
25                                 Environment.Exit (2);
26                         Console.WriteLine ("Inside = " + a);
27                         a = 3;
28                         Console.WriteLine ("After = " + a);
29                 };
30                 if (a != 1)
31                         return 3;
32                 b ();
33                 if (a != 3)
34                         return 4;
35                 Console.WriteLine ("Back, got " + a);
36                 Console.WriteLine ("Test is ok");
37                 return 0;
38         }
39 }