假设我有以下列表:
List 1:
{{"John", "Doe", "Tall", "Old"},
{"John", "Doe", "Short", "Old"},
{"Jane", "Doe", "Tall", "Young"},
{"Jane", "Doe", "Short", "Old"}}
我想在列表中搜索{“John”、“Doe”、“Short”、“Old”}。
搜索此嵌套列表条目并确保我没有得到 {"John", "Doe", "Tall", "Old"} 的最佳方法是什么?
如果嵌套列表只包含string
一项而不是四项,我将使用 LINQ 展平列表并搜索结果,List<string>.
即:
List<string> newList = oldList.SelectMany(x => x).Distinct().ToList();
newList.Contains("string");
对于每个嵌套列表包含多个字符串项的列表,我可以做类似的事情吗?