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 list.GroupBy(x => new { x.Thing, x.Color }, (key,group) => group.First());
}
}
public class Fact
{
public string Thing { get; set; }
public int Color { get; set; }
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uTGlucTsKdXNpbmcgU3lzdGVtLkNvbGxlY3Rpb25zLkdlbmVyaWM7CiAKcHVibGljIGNsYXNzIFRlc3QKewogICAgICAgIHB1YmxpYyBzdGF0aWMgdm9pZCBNYWluKCkKICAgICAgICB7CiAgICAgICAgICAgICAgICB2YXIgbGlzdCA9IG5ldyBMaXN0PEZhY3Q+ICgpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIG5ldyBGYWN0IHsgVGhpbmcgPSAiUm9zZXMgYXJlIiwgQ29sb3IgPSAweEZGMDAwMCB9LAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBuZXcgRmFjdCB7IFRoaW5nID0gIlJvc2VzIGFyZSIsIENvbG9yID0gMHhGRjAwMDAgfSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbmV3IEZhY3QgeyBUaGluZyA9ICJWaW9sZXRzIGFyZSIsIENvbG9yID0gMHgwMDAwRkYgfSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbmV3IEZhY3QgeyBUaGluZyA9ICJTdWdhciBpcyIsIENvbG9yID0gMHgxMzM3IH0sCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG5ldyBGYWN0IHsgVGhpbmcgPSAiU3VnYXIgaXMiLCBDb2xvciA9IDB4MTMzNyB9LAogICAgICAgICAgICAgICAgICAgICAgICAgICAgfTsgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICBmb3JlYWNoKHZhciBpdGVtIGluIEdldEZhY3RzKGxpc3QpKSB7CiAgICAgICAgICAgICAgICAgICAgQ29uc29sZS5Xcml0ZUxpbmUgKCJ7MDp4fSB7MTp4fSIsIGl0ZW0uVGhpbmcsIGl0ZW0uQ29sb3IpOwogICAgICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICAKICAgICAgICBwdWJsaWMgc3RhdGljIElFbnVtZXJhYmxlPEZhY3Q+IEdldEZhY3RzKElFbnVtZXJhYmxlPEZhY3Q+IGxpc3QpIHsKICAgICAgICAgICAgcmV0dXJuIGxpc3QuR3JvdXBCeSh4ID0+IG5ldyB7IHguVGhpbmcsIHguQ29sb3IgfSwgKGtleSxncm91cCkgPT4gZ3JvdXAuRmlyc3QoKSk7CiAgICAgICAgfQp9CiAKcHVibGljIGNsYXNzIEZhY3QKewogICAgcHVibGljIHN0cmluZyBUaGluZyB7IGdldDsgc2V0OyB9CiAgICBwdWJsaWMgaW50IENvbG9yIHsgZ2V0OyBzZXQ7IH0KfQog