0

lets say I have an array like this:

var items = [
 0: {},
 1: {},
 2: {},
 3: {},
 4: {},
 5: {}
]

And I know which Items i want to handle since I have figured out their index:

List<int> myIndexes = new List<int> { 0, 3, 5};

I want to get items 0, 3, 5

How would I accomplish this with a LINQ query?

looking for something like:

var myNewItems = items.Something(myIndexes)
0

2 Answers 2

1

If I understand you right, you have a collection of indexes, say

List<int> myIndexes = new List<int> { 0, 3, 5 };

to get corresponging values from items we can query these myIndexes:

var myValues = myIndexes
  .Select(index => items[index])
  .ToList();
Sign up to request clarification or add additional context in comments.

1 Comment

This makes sense. I was approaching this from focusing on fetching from items first rather than doing it the other way arround and iterating from indexes. Thanks alot and cheers.
0

try

  myIndexes.Select(i=>myNewItems[i]);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.