Question: I am wondering what is the better solution to get differences between two `List<Dictionary<string, string>>` using lambda linq with C#.

I am trying to use an expression like this but get an empty result even though both list are the same

```
var result = actualOutputList.Where(a => expectedOutputList.
            Any(e => (e.Values == a.Values) && (e.Keys == a.Keys))).ToList();

```

If I change to `!expectedOutputList` instead `expectedOutputList`, I get the full result list even though there are differences.

What should be the way to compare two `List<Dictionary<string, string>>` and get a proper List of result?

Answer: 
You can create an `IEqualityComparer` subclass for `Dictionary`:

```
public class DictionaryEqualityComparer<TKey, TValue> : IEqualityComparer<Dictionary<TKey, TValue>> {
    public bool Equals(Dictionary<TKey, TValue> d1, Dictionary<TKey, TValue> d2) {
        if (ReferenceEquals(d1, d2))
            return true;

        if (d1.Keys.Count != d2.Keys.Count)
            return false;

        foreach (var kvp in d1) {
            if (d2.TryGetValue(kvp.Key, out TValue val)) {
                if (!kvp.Value.Equals(val))
                    return false;
            }
            else
                return false;
        }

        return true;
    }

    public int GetHashCode(Dictionary<TKey, TValue> d) {
        var hc = new HashCode();
        foreach (var kvp in d.OrderBy(kvp => kvp.Key)) {
            hc.Add(kvp.Key);
            hc.Add(kvp.Value);
        }
        return hc.ToHashCode();
    }
}

```

Then you can use it with LINQ to get your answer:

```
var de = new DictionaryEqualityComparer<string,string>();
var result = expectedOutputList.Except(actualOutputList, de);

```

This returns the dictionaries missing from `actualOutputList` - if you also want any extra dictionaries, you need:

```
var result2 = expectedOutputList.Except(actualOutputList, de)
                                .Concat(actualOutputList.Except(expectedOutputList, de));

```
Also, are you sure you need to compare a list of dictionaries??

It would be good if you can give us in INPUT and expected OUTPUT example just to clarify what you expect to happen.

the below will return only the key for `a` as this is the only one that matches in both dictionaries. if you change the value of the key `b` to match up, then both key/value pairs will be returned as the result.

```cs

var myDict = new Dictionary<string, string>
        {
            { "a", "c" },
            { "b", "d" }
        };

            var otherDict = new Dictionary<string, string>
        {
            { "a", "c" },
            { "b", "e" }
        };

            var result = myDict.Where(x => otherDict.Any(t => t.Key == x.Key && t.Value == x.Value)).ToList();

```