fork download
  1. using System;
  2. using System.Globalization;
  3. using System.Linq;
  4. using System.Collections.Generic;
  5.  
  6. public class Test
  7. {
  8. public static void Main()
  9. {
  10. List<string> listA = new List<string> { "A", "A", "B", "C", "D", "E" };
  11. List<string> listRef = new List<string> { "B", "D" };
  12.  
  13. var refSet = new HashSet<string>(listRef);
  14. refSet.IntersectWith(listA);
  15. bool anyMoreThanOne = refSet.Any(rs => listA.ContainsMoreThanOnce(rs, StringComparison.OrdinalIgnoreCase));
  16. Console.Write(anyMoreThanOne);
  17. }
  18. }
  19.  
  20. public static class StringExtensions
  21. {
  22. public static bool ContainsMoreThanOnce(this IEnumerable<string> coll, String value, StringComparison comparer)
  23. {
  24. if (coll == null) throw new ArgumentNullException("col");
  25. bool contains = false;
  26. foreach (string str in coll)
  27. {
  28. if (String.Compare(value, str, comparer) == 0)
  29. {
  30. if (contains)
  31. return true;
  32. else
  33. contains = true;
  34. }
  35. }
  36. return false;
  37. }
  38. }
Success #stdin #stdout 0.03s 34008KB
stdin
Standard input is empty
stdout
False