C# Array Clear
Description
Array Clear
sets a range of elements in the Array to zero,
to false, or to null, depending on the element type.
Syntax
Array.Clear
has the following syntax.
public static void Clear(
Array array,/*from ww w . j a va 2 s.co m*/
int index,
int length
)
Parameters
Array.Clear
has the following parameters.
array
- The Array whose elements need to be cleared.index
- The starting index of the range of elements to clear.length
- The number of elements to clear.
Returns
Array.Clear
method returns
Example
The following example demonstrates the use of the Clear method with multi-dimensional arrays.
// w w w .ja va 2s .c o m
using System;
class Example
{
public static void Main()
{
int[] numbers1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
for (int i = 0; i < 9; i++)
{
Console.Write("{0} ", numbers1[i]);
}
Array.Clear(numbers1, 2, 5);
for (int i = 0; i < 9; i++)
{
Console.Write("{0} ", numbers1[i]);
}
}
}
The code above generates the following result.