blob: 42433a3e9cdb64e7a0656020c14bcc1c20e131b4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
using System;
using System.Collections.Generic;
// Dynamic statements
class Disposable : IDisposable
{
public static int Counter;
public void Dispose ()
{
++Counter;
}
public void Test ()
{
}
}
public class Test
{
bool ForEachTest ()
{
dynamic d = new List<int> { 5, 10, 7 };
dynamic res = 9;
foreach (var v in d) {
res += v;
}
return res == 31;
}
bool ForEachTest_2()
{
dynamic c = new int [] { 5, 7 };
int total = 0;
foreach (var v in c)
{
total += v;
}
return total == 12;
}
bool ForEachTest_3()
{
dynamic[] c = new dynamic [] { (byte) 1, 7 };
int total = 0;
foreach (var v in c)
{
total += v;
}
Console.WriteLine (total);
return total == 8;
}
bool UsingTest ()
{
dynamic d = new Disposable ();
try {
using (d) {
d.VV ();
}
} catch { }
if (Disposable.Counter != 1)
return false;
try {
using (dynamic u = new Disposable ()) {
u.VV ();
}
} catch { }
if (Disposable.Counter != 2)
return false;
using (dynamic u = new Disposable ()) {
u.Test ();
}
return true;
}
public static int Main ()
{
var t = new Test ();
if (!t.ForEachTest ())
return 1;
if (!t.ForEachTest_2 ())
return 2;
if (!t.ForEachTest_3 ())
return 3;
if (!t.UsingTest ())
return 10;
Console.WriteLine ("ok");
return 0;
}
}
|