zxst
zxst

Reputation: 33

linq query in list<list<T>>

I want to extract only the elements of List corresponding to a specific index from List<List>.
Tried to do this using LINQ Query and not For or Foreach, but I wasn't lucky
I want the result like below

List<List<string>> list = new List<List<string>>();
list.Add(new List<string> { "1", "2", "3" });
list.Add(new List<string> { "A", "B", "C" });

// expectation result List : index 1
// { "2", "B" }

Upvotes: 2

Views: 57

Answers (1)

MarkSouls
MarkSouls

Reputation: 999

Use Select.

int index;
list.Select(l => l[index]);

Upvotes: 1

Related Questions