[corlib] Fix a few NSLogWriter issues. (#13799)
[mono-project.git] / mcs / tests / gtest-linq-09.cs
blob5674dde864a08b66462e19c7ba2f3f9582f2712a
3 using System;
4 using System.Collections.Generic;
5 using System.Linq;
7 class Data
9 public int Key;
10 public string Value;
13 class Join
15 public static int Main ()
17 Data[] d1 = new Data[] { new Data () { Key = 1, Value = "First" } };
18 Data[] d2 = new Data[] {
19 new Data () { Key = 1, Value = "Second" },
20 new Data () { Key = 1, Value = "Third" }
24 var e = from a in d1
25 join b in d2 on a.Key equals b.Key
26 select new { Result = a.Value + b.Value };
28 var res = e.ToList ();
29 if (res.Count != 2)
30 return 1;
32 if (res [0].Result != "FirstSecond")
33 return 2;
35 if (res [1].Result != "FirstThird")
36 return 3;
38 e = from Data a in d1
39 join b in d2 on a.Key equals b.Key
40 where b.Value == "Second"
41 select new { Result = a.Value + b.Value };
43 res = e.ToList ();
44 if (res.Count != 1)
45 return 4;
47 if (res [0].Result != "FirstSecond")
48 return 5;
50 // Explicitly typed
51 e = from Data a in d1
52 join Data b in d2 on a.Key equals b.Key
53 select new { Result = a.Value + b.Value };
55 res = e.ToList ();
56 if (res.Count != 2)
57 return 10;
59 if (res [0].Result != "FirstSecond")
60 return 11;
62 if (res [1].Result != "FirstThird")
63 return 12;
65 var e2 = from Data a in d1
66 join b in d2 on a.Key equals b.Key
67 group b by a.Key;
69 var res2 = e2.ToList ();
70 if (res2.Count != 1)
71 return 20;
73 if (res2 [0].Key != 1)
74 return 21;
76 Console.WriteLine ("OK");
77 return 0;