0

I have two nested dictionaries. I need to compare the two dictionaries using LINQ query and validate that they are equal. The keys and values should match.

See example:

Dictionary<Type, Dictionary<int, int>> dict1 = new Dictionary<Type, Dictionary<int, int>> {
                {
                    Type1,
                    new Dictionary<int, int>
                    {
                        { 1, 1},
                        { 2, 1},
                        { 3, 3},
                        { 4, 4}
                    }
                },
                {
                    Type2,
                    new Dictionary<int, int>
                    {
                        { 2, 1},
                        { 1, 6},
                        { 4, 8},
                        { 3, 5}
                    }
                },

            };

Dictionary<Type, Dictionary<int, int>> dict2 = new Dictionary<Type, Dictionary<int, int>> {
                {
                    Type1,
                    new Dictionary<int, int>
                    {
                        { 1, 1},
                        { 2, 1},
                        { 3, 3},
                        { 4, 4}
                    }
                },
                {
                    Type2,
                    new Dictionary<int, int>
                    {
                        { 2, 1},
                        { 1, 6},
                        { 4, 8},
                        { 3, 5}
                    }
                },

            };

I've seen online that LINQ is the best way to do this

user3354854
  • 3
  • 1
  • 3
  • 1
    Try taking a look at this previously answered question https://stackoverflow.com/questions/21758074/c-sharp-compare-two-dictionaries-for-equality – mreyeros Jul 02 '21 at 22:57

0 Answers0