blob: ed8ba5ac4392b984480728641b930d3cb6a1bd1b (
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
|
using System;
using System.Collections.Generic;
using System.Linq;
class SelectMany
{
public static int Main ()
{
int[] a1 = new int [] { 0, 1 };
string[] a2 = new string [] { "10", "11" };
int id = 0;
// Explicitly typed
var e = from int i1 in a1
from string i2 in a2
select new { i1, i2 };
foreach (var item in e) {
Console.WriteLine (item);
if (item.i1 != id / 2)
return 1;
if (id % 2 == 0)
if (item.i2 != "10")
return 2;
++id;
}
var e2 = from int i1 in a1
where i1 > 0
from string i2 in a2
from int i3 in a1
orderby i3
select new { pp = 9, i1, i3 };
id = 0;
foreach (var item in e2) {
Console.WriteLine (item);
if (item.i1 != 1)
return 3;
if (id / 2 != item.i3)
return 4;
++id;
}
// Implicitly typed
var e3 = from i1 in a1
from i2 in a2
select new { i1, i2 };
id = 0;
foreach (var item in e3) {
Console.WriteLine (item);
if (item.i1 != id / 2)
return 1;
if (id % 2 == 0)
if (item.i2 != "10")
return 2;
++id;
}
Console.WriteLine ("OK");
return 0;
}
}
|