[英]c# collapse array list
if i have 如果我有
class foo
{
int a
int b
}
and a List<foo> myList
和
List<foo> myList
is there some short hand notation for to make a List<int> from eg myList[*].a
, ie pick out a
from each element and making a new list 是否有一些简短的符号用于
List<int> from eg myList[*].a
创建一个List<int> from eg myList[*].a
,即从每个元素中挑出a
并创建一个新的列表
clearly this can be done by iterating through myList, but seems to happen often and i was wondering if there's a shortcut notation 显然这可以通过迭代myList来完成,但似乎经常发生,我想知道是否有快捷方式表示法
same question for array etc 对于数组等同样的问题
thanks 谢谢
If you are using the C# 3.0 or higher compiler (VS2008 or up), try the following 如果您使用的是C#3.0或更高版本的编译器(VS2008或更高版本),请尝试以下操作
List<Foo> list = GetTheList();
List<int> other = list.Select(x => x.a).ToList();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.