if i have
class foo
{
int a
int b
}
and a 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
clearly this can be done by iterating through myList, but seems to happen often and i was wondering if there's a shortcut notation
same question for array etc
thanks
If you are using the C# 3.0 or higher compiler (VS2008 or up), try the following
List<Foo> list = GetTheList();
List<int> other = list.Select(x => x.a).ToList();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With