0

我有一个包含几个字符串列表的列表。

我正在寻找一个 LINQ 查询,它可以返回一个包含所有子列表中存在的所有不同字符串的列表。

是否有可能只用一个查询?

谢谢。

List<string> a = {"a", "b", "c"}
List<string> b = {"c", "d", "e"}
List<List<string>> c = {a, b}

对“c”进行查询后的预期结果:

List<string> result = {"a", "b", "c", "d", "e"}
4

1 回答 1

5

您可以先使用SelectMany先将第一个展平,然后再List<List<string>>使用Distinct

var input = new List<List<string>> {a,b};
var result = input.SelectMany(x=>x).Distinct().ToList();
于 2013-11-07T17:31:46.967 回答