选择数组中的元素,其中另一个数组中的元素为true

Mar*_*rco 1 c# linq boolean

正如我在标题中所说:我需要在另一个数组中的元素为真的位置选择数组中的元素.与Matlab命令相同的结果:

output = array1(array2);
Run Code Online (Sandbox Code Playgroud)

其中array2是bool数组.

我此刻迷失在Linq :)

Rap*_*aus 5

Where扩展方法的重载Func<TSource, int, bool> predicate是第二个参数.

其中的int参数Func<TSource, int, bool>是源的索引.

output = array1.Where((x, index) => array2[index]);
Run Code Online (Sandbox Code Playgroud)