简体   繁体   中英

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

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

Might work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM