I have two double[] X
and double[] Y
.
I want to create a new array Z, where each Zi = Xi * Yi
I wonder if it's possible to do with LINQ?
(I'm learning LINQ now; of course I can use plain for).
I have two double[] X
and double[] Y
.
I want to create a new array Z, where each Zi = Xi * Yi
I wonder if it's possible to do with LINQ?
(I'm learning LINQ now; of course I can use plain for).
If you don't want to use a 3rd party lib or .NET 4.0, you could use 'Select'
double[] z = x.Select((d, i) => d * y[i]).ToArray();
'i' is the index of element 'd' for the current iteration and it's used here to retrieve the accordant element from y.