I have two array definition and I want to do addition operation element by element without looping operation? for example:
decimal[] xx = { 1, 2, 3 };
decimal[] yy = { 6, 7, 8 };
the result I want is:
decimal[] zz = { 7, 9, 11 };
the addition operation is simple. Just add one by one for each element like
decimal[] zz = decimal[xx.Length];
for (int i=0; i<xx.Length;i++){
zz[i] =xx[i] + yy[i];
}
But I don’t want to use looping operation.
You can’t do that without looping some way or the other.
Your array creation and loop should be:
Or a more compact, but somewhat less readable version:
You can also use Linq extensions to do the looping:
Or: