fork download
  1. using System;
  2. using System.Linq;
  3.  
  4. public class Test
  5. {
  6. public static void Main()
  7. {
  8.  
  9. var data = new[] {
  10. new Something {SomeIntProperty=1, SomeStringProperty="A"}
  11. , new Something {SomeIntProperty=2, SomeStringProperty="A"}
  12. , new Something {SomeIntProperty=3, SomeStringProperty="A"}
  13. , new Something {SomeIntProperty=4, SomeStringProperty="A"}
  14. , new Something {SomeIntProperty=5, SomeStringProperty="A"}
  15. , new Something {SomeIntProperty=6, SomeStringProperty="B"}
  16. , new Something {SomeIntProperty=7, SomeStringProperty="B"}
  17. , new Something {SomeIntProperty=8, SomeStringProperty="C"}
  18. , new Something {SomeIntProperty=9, SomeStringProperty="D"}
  19. };
  20. var dict = data.GroupBy(s => s.SomeStringProperty)
  21. .ToDictionary(g => g.Key);
  22. foreach (var key in dict.Keys) {
  23. if (data.Any(s => ReferenceEquals(s.SomeStringProperty, key))) {
  24. Console.WriteLine("Key '{0}' is present.", key);
  25. } else {
  26. Console.WriteLine("Key '{0}' is not present.", key);
  27. }
  28. }
  29.  
  30. }
  31. }
  32.  
  33. public class Something
  34. {
  35. public int SomeIntProperty { get; set; }
  36. public string SomeStringProperty { get; set; }
  37. }
Success #stdin #stdout 0.02s 131648KB
stdin
Standard input is empty
stdout
Key 'A' is present.
Key 'B' is present.
Key 'C' is present.
Key 'D' is present.