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 = 1337 },
new Fact { Thing = "Sugar is", Color = 1337 },
};
foreach(var item in GetFacts(list)) {
Console.WriteLine ("{0} {1}", item.Thing, item.Color);
}
}
public static IEnumerable<Fact> GetFacts(IEnumerable<Fact> list) {
return list.Select(x => new { x.Thing, x.Color } ).Distinct();
}
}
public class Fact
{
public string Thing { get; set; }
public int Color { get; set; }
}
CnVzaW5nIFN5c3RlbTsKdXNpbmcgU3lzdGVtLkxpbnE7CnVzaW5nIFN5c3RlbS5Db2xsZWN0aW9ucy5HZW5lcmljOwogCnB1YmxpYyBjbGFzcyBUZXN0CnsKICAgICAgICBwdWJsaWMgc3RhdGljIHZvaWQgTWFpbigpCiAgICAgICAgewogICAgICAgICAgICAgICAgdmFyIGxpc3QgPSBuZXcgTGlzdDxGYWN0PiAoKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBuZXcgRmFjdCB7IFRoaW5nID0gIlJvc2VzIGFyZSIsIENvbG9yID0gMHhGRjAwMDAgfSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbmV3IEZhY3QgeyBUaGluZyA9ICJSb3NlcyBhcmUiLCBDb2xvciA9IDB4RkYwMDAwIH0sCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG5ldyBGYWN0IHsgVGhpbmcgPSAiVmlvbGV0cyBhcmUiLCBDb2xvciA9IDB4MDAwMEZGIH0sCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG5ldyBGYWN0IHsgVGhpbmcgPSAiU3VnYXIgaXMiLCBDb2xvciA9IDEzMzcgfSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbmV3IEZhY3QgeyBUaGluZyA9ICJTdWdhciBpcyIsIENvbG9yID0gMTMzNyB9LAogICAgICAgICAgICAgICAgICAgICAgICAgICAgfTsgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICBmb3JlYWNoKHZhciBpdGVtIGluIEdldEZhY3RzKGxpc3QpKSB7CiAgICAgICAgICAgICAgICAgICAgQ29uc29sZS5Xcml0ZUxpbmUgKCJ7MH0gezF9IiwgaXRlbS5UaGluZywgaXRlbS5Db2xvcik7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIAogICAgICAgIHB1YmxpYyBzdGF0aWMgSUVudW1lcmFibGU8RmFjdD4gR2V0RmFjdHMoSUVudW1lcmFibGU8RmFjdD4gbGlzdCkgewogICAgICAgICAgICByZXR1cm4gbGlzdC5TZWxlY3QoeCA9PiBuZXcgeyB4LlRoaW5nLCB4LkNvbG9yIH0gKS5EaXN0aW5jdCgpOwogICAgICAgIH0KfQoKcHVibGljIGNsYXNzIEZhY3QKewogICAgcHVibGljIHN0cmluZyBUaGluZyB7IGdldDsgc2V0OyB9CiAgICBwdWJsaWMgaW50IENvbG9yIHsgZ2V0OyBzZXQ7IH0KfQo=
prog.cs(23,13): error CS0266: Cannot implicitly convert type `System.Collections.Generic.IEnumerable<anonymous type>' to `System.Collections.Generic.IEnumerable<Fact>'. An explicit conversion exists (are you missing a cast?)
Compilation failed: 1 error(s), 0 warnings