【发布时间】:2018-06-09 07:55:37
【问题描述】:
我有一个具有双重值的元组列表:
List<Tuple<string, string>> Descriptions;
我一直在添加内容,就像这样:
Descriptions.Add (new Tuple<string, string> ("max", "some description"));
Descriptions.Add (new Tuple<string, string> ("joe", "some description"));
Descriptions.Add (new Tuple<string, string> ("jane", "some description"));
Descriptions.Add (new Tuple<string, string> ("max", "some other description"));
我想使用 Linq 检索一个列表,其中元组中的 Item1 是一个特定值,例如 "max"。我可以使用这段代码:
var s = Descriptions.Where (x => x.Item1 == "max");
但这会给 s 分配一个元组列表,这是我不想要的。我只想要一个描述字符串的列表,也就是说,它应该返回一个list<string>,其中包含与Item1字符串"max"关联的所有描述。
【问题讨论】:
标签: c# list linq collections tuples