fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. class Sample
  6. {
  7. public string Value1 { get; set; }
  8. public string Value2 { get; set; }
  9. public override string ToString() {
  10. return Value1 + "/" + Value2;
  11. }
  12. }
  13.  
  14. public class Test
  15. {
  16. public static void Main()
  17. {
  18. var list = new List<Sample>() {
  19. new Sample{ Value1 = "Apple", Value2="Red" },
  20. new Sample{ Value1 = "Banana", Value2="Yellow" },
  21. new Sample{ Value1 = "Lemon", Value2="Yellow" },
  22. };
  23.  
  24. var s = new HashSet<string>();
  25. list = list.Where(n => s.Add(n.Value2)).ToList();
  26.  
  27. foreach (var n in list) {
  28. Console.WriteLine(n);
  29. }
  30. }
  31. }
Success #stdin #stdout 0.03s 33944KB
stdin
Standard input is empty
stdout
Apple/Red
Banana/Yellow