Home > Mobile >  How to get arr[arr[i]] from a list using Linq?
How to get arr[arr[i]] from a list using Linq?

Time:08-11

Edit 1: Can I rewrite this code using LINQ? Assuming the list contains values between [0,N-1] where N = size of the array.

List<int> list = new List<int>(){2, 3, 0, 1, 4};
for(int i =0; i < list.Count; i  )
{
  list[i] = list[i] * list.Count   list[list[i]];           
}

CodePudding user response:

Obviously, LINQ was not created to update anything (Q in the abbreviation), but there`s is Select method, which allow you to do similar.

var result = list.Select(item => item * list.Count   list[item]);

That way you will query your data into new form, what is not update, but creating new object with separate values.

  • Related