Fastest way to find common items across multiple lists in C#

后端 未结 11 1847

Given the following:

List> optionLists;

what would be a quick way to determine the subset of Option objects that a

11条回答
  •  面向向阳花
    2021-01-19 02:59

    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;
    

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

提交回复
热议问题