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
  23. from x in list.GroupBy(x => new {x.Thing, x.Color })
  24. select x.First();
  25. }
  26. }
  27.  
  28. public class Fact
  29. {
  30. public string Thing { get; set; }
  31. public int Color { get; set; }
  32. }
Success #stdin #stdout 0.06s 34216KB
stdin
Standard input is empty
stdout
Roses are ff0000
Violets are ff
Sugar is 1337