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: 9f4897a82f4f3368b34e6cb030c00f2876ba3815 (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
//
// 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;

		//
		// implicit block
		//
		foreach (object a in x)
			total += (int) a;
		if (total != 6)
			return 2;
		
		return 0;
	}
}