如何在列表中查找重复项并按出现次数对其进行排序 [英] How to find duplicates in list and sort them by number of appearance

查看:437
本文介绍了如何在列表中查找重复项并按出现次数对其进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种简单的方法来查找列表中的重复项,然后按出现次数对它们进行排序?另外,应删除重复项.

Is there a easy way to find duplicates in list, and then sort them by number of appearance? Also, duplicates should be removed.

例如.您有这样的List<String>:

List<String> = new List<String>{"6","1","2","2","4","6","5","1","6","6","2"};

问题是,如何将此列表转换为->"6","1","2","4","5"?

Question is, how to convert this list into -> "6", "1", "2", "4", "5"?

推荐答案

使用Linq.Distinct()

List<String> list = new List<String>{"6","1","2","2","4","6","5","1","6","6","2"};
list = list.Distinct().ToList();

这篇关于如何在列表中查找重复项并按出现次数对其进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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