score:5

Accepted answer

You can achieve this using LINQ:

double[] a = new double[]{1.0, 2.0, 3.0}; 
bool[] b = new bool[]{true, false, true}; 
var result = a.Where((item, index)=>b[index]);

score:6

Use LINQ Zip method, e.g.:

a.Zip(b, (i, j) => new {i, j}).Where(x => x.j).Select(x => x.i)

score:4

There's also this more traditional LINQ approach:

b.Select((f, i) => f ? i : - 1).Where(i => i != -1).Select(i => a[i]);

Related Articles