【发布时间】:2015-10-11 23:47:50
【问题描述】:
我有一个结构列表:
struct MyStruct{
int ID;
string name;
string surname;
}
List<MyStruct> list1 = new List<MyStruct>();
///here the list is being updated so that it has some elements
现在我想从 list1 中提取所有 ID 并放入另一个列表:
List<int> list2 = new List<int>();
list2.AddRange(list1.GetIds() /*LINQ HERE*/);
诀窍是我想使用 LINQ 来完成它,但我仍然不太了解它。我知道它可以用普通的 for 循环 来完成,但 我想使用 AddRange 和 LINQ。
【问题讨论】: