blob: c436c318e776c1fd207e7854a5d78b96fac5428b (
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
|
//
// This program excercises invoking foreach on structures
// that implement GetEnumerator
//
using System;
using System.Collections;
struct X {
int [] a;
public IEnumerator GetEnumerator ()
{
a = new int [3] { 1, 2, 3};
return a.GetEnumerator ();
}
}
class Y {
static X x;
static int Main ()
{
int total = 0;
x = new X ();
foreach (object a in x){
total += (int) a;
}
if (total != 6)
return 1;
total = 0;
foreach (object a in new X ()){
total += (int) a;
}
if (total != 6)
return 3;
total = 0;
//
// implicit block
//
foreach (object a in x)
total += (int) a;
if (total != 6)
return 2;
return 0;
}
}
|