C # convolution list

if I have

class foo
{ 
   int a
   int b
}

and a List<foo> myList

is there a short notation in order to make a List<int> from eg myList[*].a, i.e. select afrom each item and create a new list

it’s clear that this can be done by iterating through myList, but it seems to happen often, and I was wondering if there is a label notation

same question for array etc.

thanks

+3
source share
1 answer

If you are using a C # 3.0 compiler or higher (VS2008 or higher), try the following

List<Foo> list = GetTheList();
List<int> other = list.Select(x => x.a).ToList();
+11
source

Source: https://habr.com/ru/post/1716803/


All Articles