Reputation: 9943
I have the following array and I just want to get the index 7 and 8 from every element. Is there a Linq way to do this without creating a class ?
When I do this split.Select(d => d.ElementAt(7)).ToList()
I create new array with element 7 but I also need the element 8 here.
I tried split.Select(a => new { a[7], a[8] }).ToList()
but I get a message that says
Invalid anonymous type member declarator. Anonymous type members must be declared with a member assignment, simple name or member access.
Upvotes: 1
Views: 190
Reputation: 56463
The following will yield a List<string[]>
split.Select(a => new[] { a[7], a[8] } ).ToList();
and the following List<List<string>>
split.Select(a => new List<string> { a[7], a[8] } ).ToList();
Upvotes: 3