Remove Duplicates from List of Dictionaries in C#

Share this

In this article, I will demonstrate how to remove duplicates from List of Dictionaries in C# using LINQ.

Following figure gives an overview of the generic interfaces and the generic classes of dictionaries. White boxes represent interfaces and the grey boxes represent classes. .NET models dictionaries as IEnumerables and ICollections at the highest levels of abstractions. From the figure we can directly read that a dictionary is a ICollection of KeyValuePairs.

I have a list of dictionaries of as follows:-

The objective is to remove the exact duplicate dictionaries from the List. The output should be a list having unique dictionaries where every dictionary in the list has unique key/value pair.

You can see that in the above List, the dictionary { “A”, “Apple” }, { “B”, “Ball” } is a duplicate.

Using the below LINQ, the filtered list of dictionaries can be obtained as shown below.

The resulting List of dictionaries without duplicates will contain:

I hope you followed the article. If you have any comments, questions or suggestions, leave a message and I will try to respond at my earliest.

Share this

Leave a Reply