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