Is it possible to set all int array values to 0 with Lambda/Linq?
public int[] Reset()
{
int[] M = new int[MIlg]; \\MIlg - length of array
for (int i = 0; i < M.Length; i++)
{
M[i] = 0;
}
return M;
}
LINQ is inherently about querying, not modifying. But there's already a method that does this - Array.Clear
:
Array.Clear(array, 0, array.Length);
That's assuming you want to clear an existing array, of course. Your current method doesn't make much sense, as a new array already starts with every element set to the default, so you can just use new int[length]
. I'd expect a method called Reset
to affect an existing array.
See more on this question at Stackoverflow