StackOverflowVeryHelpful
StackOverflowVeryHelpful

Reputation: 2427

Unique Dictionaries in a list of dictionaries(c#)

I want to create a generic class which helps me to compare two dictionary (both keys and values)

class DictionaryComparer : IEqualityComparer<Dictionary<TKey, TValue>> //doesn't work. But i want to make it generic

class DictionaryComparer : IEqualityComparer<Dictionary<string,string>> //works. Not generic

I would use the reference of IEqualityComparer using Distinct(IEqualityComparer<Dictionary<string,string>> comparer) on a List<Dictionary<string,string>> . So that i have only unique dictionaries in a list.

Is there any better way have unique dictionaies in a list

Upvotes: 1

Views: 173

Answers (1)

LMB
LMB

Reputation: 1135

class DictionaryComparer<TKey, TValue> 
    : IEqualityComparer<Dictionary<TKey, TValue>>

Might work.

Upvotes: 4

Related Questions