I am learning LINQ and have a very simple question that I think will help my understand the technology better. How can I find the product of an array of ints?
For example, what is the LINQ way to do:
int[] vals = { 1, 3, 5 }; return vals[0] * vals[1] * vals[2];
This would work:
You’re starting with a seed of
1and then the function is called for each of your values with two arguments,accwhich is the current accumulated value, andvalwhich is the value in the array; the function multiplies the current accumulated value by the value in the array and the result of that expression is passed asaccto the next function. i.e. the chain of function calls with the array you provided will be: