Welcome to mirror list, hosted at ThFree Co, Russian Federation.

test-36.cs « tests « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: dc6fafe434623ae22c6e0fd9837902b10531acc4 (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;

	public 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;
	}
}