using System;
using System.Linq;
using System.Collections.Generic;
public class Test
{
public static void Main()
{
var list = new List<Fact> () {
new Fact { Thing = "Roses are", Color = 0xFF0000 },
new Fact { Thing = "Roses are", Color = 0xFF0000 },
new Fact { Thing = "Violets are", Color = 0x0000FF },
new Fact { Thing = "Sugar is", Color = 0x1337 },
new Fact { Thing = "Sugar is", Color = 0x1337 },
};
foreach(var item in GetFacts(list)) {
Console.WriteLine ("{0:x} {1:x}", item.Thing, item.Color);
}
}
public static IEnumerable<Fact> GetFacts(IEnumerable<Fact> list) {
return
from x in list
group x by new { x.Thing, x.Color } into grp
select grp.First();
}
}
public class Fact
{
public string Thing { get; set; }
public int Color { get; set; }
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uTGlucTsKdXNpbmcgU3lzdGVtLkNvbGxlY3Rpb25zLkdlbmVyaWM7CiAKcHVibGljIGNsYXNzIFRlc3QKewogICAgICAgIHB1YmxpYyBzdGF0aWMgdm9pZCBNYWluKCkKICAgICAgICB7CiAgICAgICAgICAgICAgICB2YXIgbGlzdCA9IG5ldyBMaXN0PEZhY3Q+ICgpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIG5ldyBGYWN0IHsgVGhpbmcgPSAiUm9zZXMgYXJlIiwgQ29sb3IgPSAweEZGMDAwMCB9LAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBuZXcgRmFjdCB7IFRoaW5nID0gIlJvc2VzIGFyZSIsIENvbG9yID0gMHhGRjAwMDAgfSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbmV3IEZhY3QgeyBUaGluZyA9ICJWaW9sZXRzIGFyZSIsIENvbG9yID0gMHgwMDAwRkYgfSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbmV3IEZhY3QgeyBUaGluZyA9ICJTdWdhciBpcyIsIENvbG9yID0gMHgxMzM3IH0sCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG5ldyBGYWN0IHsgVGhpbmcgPSAiU3VnYXIgaXMiLCBDb2xvciA9IDB4MTMzNyB9LAogICAgICAgICAgICAgICAgICAgICAgICAgICAgfTsgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICBmb3JlYWNoKHZhciBpdGVtIGluIEdldEZhY3RzKGxpc3QpKSB7CiAgICAgICAgICAgICAgICAgICAgQ29uc29sZS5Xcml0ZUxpbmUgKCJ7MDp4fSB7MTp4fSIsIGl0ZW0uVGhpbmcsIGl0ZW0uQ29sb3IpOwogICAgICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICAKICAgICAgICBwdWJsaWMgc3RhdGljIElFbnVtZXJhYmxlPEZhY3Q+IEdldEZhY3RzKElFbnVtZXJhYmxlPEZhY3Q+IGxpc3QpIHsKICAgICAgICAgICAgcmV0dXJuIAogICAgICAgICAgICAgICAgIGZyb20geCBpbiBsaXN0CiAgICAgICAgICAgICAgICAgZ3JvdXAgeCBieSBuZXcgeyB4LlRoaW5nLCB4LkNvbG9yIH0gaW50byBncnAKICAgICAgICAgICAgICAgICBzZWxlY3QgZ3JwLkZpcnN0KCk7ICAgICAgICAgICAgICAgICAKICAgICAgICB9Cn0KIApwdWJsaWMgY2xhc3MgRmFjdAp7CiAgICBwdWJsaWMgc3RyaW5nIFRoaW5nIHsgZ2V0OyBzZXQ7IH0KICAgIHB1YmxpYyBpbnQgQ29sb3IgeyBnZXQ7IHNldDsgfQp9