fork download
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. public class Test
  6. {
  7. public static void Main()
  8. {
  9. var list = new List<Fact> () {
  10. new Fact { Thing = "Roses are", Color = 0xFF0000 },
  11. new Fact { Thing = "Roses are", Color = 0xFF0000 },
  12. new Fact { Thing = "Violets are", Color = 0x0000FF },
  13. new Fact { Thing = "Sugar is", Color = 0x1337 },
  14. new Fact { Thing = "Sugar is", Color = 0x1337 },
  15. };
  16. foreach(var item in GetFacts(list)) {
  17. Console.WriteLine ("{0:x} {1:x}", item.Thing, item.Color);
  18. }
  19. }
  20.  
  21. public static IEnumerable<Fact> GetFacts(IEnumerable<Fact> list) {
  22. return list.Select(x => new { x.Thing, x.Color } ).Distinct().Select(x => new Fact { Thing = x.Thing, Color = x.Color });
  23. }
  24. }
  25.  
  26. public class Fact
  27. {
  28. public string Thing { get; set; }
  29. public int Color { get; set; }
  30. }
  31.  
Success #stdin #stdout 0.05s 34104KB
stdin
Standard input is empty
stdout
Roses are ff0000
Violets are ff
Sugar is 1337