mono-2.6.7-for-amiga /mcs/tests/gtest-linq-10.cs

Language C# Lines 70
MD5 Hash 08b513613318027cf2b49885bc3fcbb5 Estimated Cost $1,090 (why?)
Repository https://bitbucket.org/steenlund/mono-2.6.7-for-amiga View Raw File View Project SPDX
 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
using System;
using System.Collections.Generic;
using System.Linq;

class DataA
{
	public int Key;
	public string Text;
}

class DataB
{
	public int Key;
	public string Value;	
}

class GroupJoin
{
	public static int Main ()
	{
		DataA[] d1 = new DataA[] { new DataA () { Key = 1, Text = "Foo" }};
		DataB[] d2 = new DataB[] { new DataB () { Key = 2, Value = "Second" }};
		
		var e = from a in d1
			join b in d2 on a.Key equals b.Key into ab
			from x in ab.DefaultIfEmpty ()
			select new { a = x == default (DataB) ? "<empty>" : x.Value, b = a.Text };

		var res = e.ToList ();
		if (res.Count != 1)
			return 1;
		
		if (res [0].a != "<empty>")
			return 2;
			
		if (res [0].b != "Foo")
			return 3;
			
		// Explicitly typed
		e = from a in d1
			join DataB b in d2 on a.Key equals b.Key into ab
			from x in ab.DefaultIfEmpty ()
			select new { a = x == default (DataB) ? "<empty>" : x.Value, b = a.Text };
			
		foreach (var o in e)
			Console.WriteLine (o);
			
		res = e.ToList ();
		if (res.Count != 1)
			return 10;
		
		if (res [0].a != "<empty>")
			return 11;
			
		if (res [0].b != "Foo")
			return 12;
			
		// FIXME: Used same name
		//var e2 = from a in d1
		//	join a in d2 on a.Key equals a.Key into ab
		//	select a;
		
		Console.WriteLine ("OK");
		return 0;
	}
}
Back to Top