列表中的最大回报重复项 [英] Return max repeated item in list

查看:144
本文介绍了列表中的最大回报重复项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

        List<string> prod = new List<string>();
        prod.Add("dfg");
        prod.Add("dfg");
        prod.Add("ojj");
        prod.Add("dfg");
        prod.Add("e");

在上面的code督促列表中包含了项东风重复3次(最大计数)...
我想要的东风的输出,因为这个项目是重复最大次数。
在这个任何人都可以帮助

In the above code prod List has item "dfg" repeated thrice(max count)... I want "dfg" as the output because this item is repeated maximum times. Can anyone help in this

推荐答案

您可以使用LINQ:

string maxRepeated = prod.GroupBy(s => s)
                         .OrderByDescending(s => s.Count())
                         .First().Key;

这篇关于列表中的最大回报重复项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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