You can call Array.Clear :
int[] x = new int[10]; for (int i = 0; i < 10; i++) { x[i] = 5; } Array.Clear(x, 0, x.Length);
Alternatively, depending on the situation, you may find it easier to create a new array instead. In particular, you don't have to worry about whether any other code has an array reference and expects the old values โโto be there.
I canโt remember ever calling Array.Clear in my own code - this is just not what I need.
(Of course, if you replace all the values โโanyway, you can do this without clearing the array first).
Jon skeet
source share