在C#中跨多个列表查找通用项目的最快方法 [英] Fastest way to find common items across multiple lists in C#

查看:51
本文介绍了在C#中跨多个列表查找通用项目的最快方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给出以下内容:

List<List<Option>> optionLists;

什么是确定出现在所有N个列表中的Option对象子集的快速方法?平等是通过一些字符串属性(例如option1.Value == option2.Value)确定的.

what would be a quick way to determine the subset of Option objects that appear in all N lists? Equality is determined through some string property such as option1.Value == option2.Value.

所以我们应该以 List< Option> 结尾,其中每个项目仅出现一次.

So we should end up with List<Option> where each item appears only once.

推荐答案

好的,这将找到在每个 列表中都出现一个值的Option对象的列表.

Ok, this will find the list of Option objects that have a Value appearing in every list.

var x = from list in optionLists
        from option in list
        where optionLists.All(l => l.Any(o => o.Value == option.Value))
        orderby option.Value
        select option;

它不会进行不同"选择,因此它将返回多个Option对象,其中一些具有相同的Value.

It doesn't do a "distinct" select so it'll return multiple Option objects, some of them with the same Value.

这篇关于在C#中跨多个列表查找通用项目的最快方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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