.net 如何查询List中某个出现次数大于2次的元素

GoodDbye 2014-12-02 04:35:01
List<string> listname = new List<string>();
Queue<List<string>> listQue = new Queue<List<string>>(3);
List<string> list1 = new List<string>() { "阿里", "腾讯", "百度" };
List<string> list2 = new List<string>() { "苹果", "微软", "谷歌", "FaceBook", "英特尔", "吉利德", "亚马逊" };
List<string> list3 = new List<string>() { "苹果", "微软", "甲骨文", "英特尔", "IBM", "高通" };
List<string> list4 = new List<string>() { "苹果", "微软", "谷歌", "阿里", "FaceBook", "腾讯", "百度", "亚马逊", "京东" };
List<string> list5 = new List<string>() { "阿里", "腾讯", "亚马逊", "京东" };
List<string> list6 = new List<string>() { "58", "赶集", "高通", "甲骨文", "索尼" };
listQue.Enqueue(list1);
listQue.Enqueue(list2);
listQue.Enqueue(list3);
if (listQue.Count == 3)
{
//判断某个元素出现2次,把该元素加到listname里面(list1,list2和list3中出现2次以上的元素,是“苹果”,“微软”,“英特尔”)
//接着list1出队,list4入队,在执行一次if里面的方法
//即list2,list3和list4的元素出现2次以上,即“苹果”,“微软”,“谷歌”,“Facebook”,“英特尔”和“亚马逊”6个元素
}
求大神给个思路哇
...全文
829 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
GoodDbye 2014-12-02
  • 打赏
  • 举报
回复
引用 1 楼 starfd 的回复:
Queue<List<string>> listQue = new Queue<List<string>>(3);
            var query = from q in listQue
                        let t = q
                        from s in t
                        select s;
            var query2 = from q in query
                         group q by q into g
                         where g.Count() > 1
                         let t = g
                         from s in t
                         select s;
已解决,感谢,分都给你了
GoodDbye 2014-12-02
  • 打赏
  • 举报
回复
引用 1 楼 starfd 的回复:
Queue<List<string>> listQue = new Queue<List<string>>(3);
var query = from q in listQue
let t = q
from s in t
select s;
var query2 = from q in query
group q by q into g
where g.Count() > 1
let t = g
from s in t
select s;


亲,为什么我把结果foreach输出是输出2次,你这不是group by了么
exception92 2014-12-02
  • 打赏
  • 举报
回复
#1 正解。
而立大叔 2014-12-02
  • 打赏
  • 举报
回复
使用LINQ进行处理
  • 打赏
  • 举报
回复
Queue<List<string>> listQue = new Queue<List<string>>(3);
            var query = from q in listQue
                        let t = q
                        from s in t
                        select s;
            var query2 = from q in query
                         group q by q into g
                         where g.Count() > 1
                         let t = g
                         from s in t
                         select s;

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧