How to select elements from an array using an array of indices with Linq?
The following code works:
String[] A = new String[] { "one", "two", "three", "four" }; int[] idxs = new int[] { 1, 3 }; String[] B = new String[idxs.Length]; for (int i = 0; i < idxs.Length; i++) { B[i] = A[idxs[i]]; } System.Diagnostics.Debug.WriteLine(String.Join(", ", B));
output:
two, four
Is there a LINQ (or other single line) way to get rid of the for loop?
source share