In class/Microsoft.Build.Tasks/Microsoft.Build.Tasks:
[mcs.git] / tests / gtest-lambda-01.cs
blobeb4a5e3e51344fa9adb7d2ff361e9b82bd09cc1c
2 //
3 // Lambda expression test, basics.
4 //
5 using System;
7 delegate int IntFunc (int x);
8 delegate void VoidFunc (int x);
10 class X {
12 static IntFunc func, increment;
13 static VoidFunc nothing;
15 static int Main ()
17 int y = 0;
18 int r;
21 // The following tests body-style lambda
23 increment = (int x) => { return x + 1; };
24 r = increment (4);
25 Console.WriteLine ("Should be 5={0}", r);
26 if (r != 5)
27 return 1;
30 // This tests the body of a lambda being an expression
32 func = (int x) => x + 1;
33 r = func (10);
34 Console.WriteLine ("Should be 11={0}", r);
35 if (r != 11)
36 return 2;
39 // The following tests that the body is a statement
41 nothing = (int x) => { y = x; };
42 nothing (10);
43 Console.WriteLine ("Should be 10={0}", y);
44 if (y != 10)
45 return 3;
47 nothing = (int x) => { new X (x); };
48 nothing (314);
49 if (instantiated_value != 314)
50 return 4;
52 Console.WriteLine ("All tests pass");
53 return 0;
56 static int instantiated_value;
58 X (int v)
60 instantiated_value = v;