如何从列表中删除重复的C# [英] How to remove duplicates from a list in C#

查看:112
本文介绍了如何从列表中删除重复的C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从此列表中删除重复项:

I want to remove duplicates from this list:

List<Dictionary<string, object>> val = new List<Dictionary<string, object>>();

如果我以这种方式应用Distinct(),则不起作用:

It does not work if I apply Distinct() in this way:

 List<Dictionary<string, object>> result = val.Distinct().ToList<Dictionary<string, object>>()

问题现在解决了。我使用MySQL union命令从数据库中读取表。

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 是一个 Comparer Class 。您可以在此课程中实现比较逻辑。

where myDictionaryComparer is a Comparer Class. You can implement your comparison logic in this class.

这篇关于如何从列表中删除重复的C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆