int[] x
int[] array_of_new_values
for(int i = 0 ; i < x.Length && i < array_of_new_values.Length ;i++)
{
x[i] = array_of_new_values[i]; // this will give x[i] its new value
}
The static Array.Clear() method "sets a range of elements in the Array to zero, to false, or to Nothing, depending on the element type". If you want to clear your entire array, you could use this method an provide it 0 as start index and myArray.Length as length:
Why clear it? Just assign new values.
Wouldnt it be easier to use a list instead.
And then:
And to clear:
This is not correct answer for your post but you can use this logic according to your need. Here is a code Snippets taken from here
and output of this is:
Why not just create new array and assign it to existing array variable?
For two dimensional arrays, you should do as bellow:
The static
Array.Clear()
method "sets a range of elements in the Array to zero, to false, or to Nothing, depending on the element type". If you want to clear your entire array, you could use this method an provide it0
as start index andmyArray.Length
as length: