如何在C#中的列表中删除重复项 [英] How to remove duplicates from a list in C#
本文介绍了如何在C#中的列表中删除重复项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从列表中删除重复的:
I want to remove duplicates from this list:
List<Dictionary<string, object>> val = new List<Dictionary<string, object>>();
如果我申请鲜明的()这样它不工作:
It does not work if I apply Distinct() in this way:
List<Dictionary<string, object>> result = val.Distinct().ToList<Dictionary<string, object>>()
更新:问题现在解决了。我用MySQL的联合命令从数据库中读取表。
Update: Problem is now solved. I used the MySQL union command to read table from the database.
推荐答案
试试这个:
List<Dictionary<string, object>> result = val.Distinct(new myDictionaryComparer()).ToList();
其中, myDictionaryComparer
是的比较器类。您可以实现比较逻辑在这个类。
where myDictionaryComparer
is a Comparer Class. You can implement your comparison logic in this class.
这篇关于如何在C#中的列表中删除重复项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文