EnumerableSequenceEqualTest.cs 935 B

123456789101112131415161718192021222324252627282930313233
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace ConsoleApp1.Else
  7. {
  8. internal class EnumerableSequenceEqualTest
  9. {
  10. public static void Test()
  11. {
  12. var a = new Dictionary<string, string>() {
  13. { "0", "1" },
  14. { "2", "3" }
  15. };
  16. var b = new Dictionary<string, string>() {
  17. { "2", "3" },
  18. { "0", "1" }
  19. };
  20. var equl = CheckIsEqual(a, b);
  21. }
  22. private static bool CheckIsEqual(Dictionary<string, string> d1, Dictionary<string, string> d2)
  23. {
  24. return d1.Count == d2.Count && d1.All(
  25. (d1KV) => d2.TryGetValue(d1KV.Key, out var d2Value) && (
  26. d1KV.Value == d2Value ||
  27. d1KV.Value?.Equals(d2Value) == true)
  28. );
  29. }
  30. }
  31. }