using System;
using System.Linq;
public class Test
{
public static void Main()
{
var list1 = new[] { new { ID = 1 }, new { ID = 2 }, new { ID = 3 } };
var list2 = new[] {
new {
ID = 1,
Name = "Jason"
},
new {
ID = 1,
Name = "Jim"
},
new {
ID = 2,
Name = "Mike"
},
new {
ID = 3,
Name = "Phil"
}
};
var lst = (
from lst1 in list1
join lst2 in list2 on lst1.ID equals lst2.ID into lstGroup
select lstGroup.First()
);
foreach(var item in lst)
{
Console.WriteLine("ID: {0}, Name: {1}", item.ID, item.Name);
}
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uTGlucTsKCnB1YmxpYyBjbGFzcyBUZXN0CnsKCXB1YmxpYyBzdGF0aWMgdm9pZCBNYWluKCkKCXsKdmFyIGxpc3QxID0gbmV3W10geyBuZXcgeyBJRCA9IDEgfSwgbmV3IHsgSUQgPSAyIH0sIG5ldyB7IElEID0gMyB9IH07CnZhciBsaXN0MiA9IG5ld1tdIHsKCW5ldyB7CgkJSUQgPSAxLAoJCU5hbWUgPSAiSmFzb24iCgl9LAoJbmV3IHsgCgkJSUQgPSAxLAoJCU5hbWUgPSAiSmltIgoJfSwKCW5ldyB7CgkJSUQgPSAyLAoJCU5hbWUgPSAiTWlrZSIKCX0sCgluZXcgewoJCUlEID0gMywKCQlOYW1lID0gIlBoaWwiCgl9Cn07Cgp2YXIgbHN0ID0gKAoJZnJvbSBsc3QxIGluIGxpc3QxCglqb2luIGxzdDIgaW4gbGlzdDIgb24gbHN0MS5JRCBlcXVhbHMgbHN0Mi5JRCBpbnRvIGxzdEdyb3VwCglzZWxlY3QgbHN0R3JvdXAuRmlyc3QoKQopOwoKCQlmb3JlYWNoKHZhciBpdGVtIGluIGxzdCkKCQl7CgkJCUNvbnNvbGUuV3JpdGVMaW5lKCJJRDogezB9LCBOYW1lOiB7MX0iLCBpdGVtLklELCBpdGVtLk5hbWUpOwoJCX0KCX0KfQ==