Clear Method

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

Sets a range of elements in the Array to zero, to false, or to nullNothingnullptrunita null reference (Nothing in Visual Basic), depending on the element type.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

public static void Clear(
	Array array,
	int index,
	int length
)

Parameters

array
Type: System..::..Array
The Array whose elements need to be cleared.
index
Type: System..::..Int32
The starting index of the range of elements to clear.
length
Type: System..::..Int32
The number of elements to clear.

ExceptionCondition
ArgumentNullException

array is nullNothingnullptrunita null reference (Nothing in Visual Basic).

IndexOutOfRangeException

index is less than the lower bound of array.

-or-

length is less than zero.

-or-

The sum of index and length is greater than the size of the Array.

Reference-type elements are set to nullNothingnullptrunita null reference (Nothing in Visual Basic). Boolean-type elements are set to false. Other value-type elements are set to zero.

The range of cleared elements wrap from row to row in a multi-dimensional array.

This method only clears the values of the elements; it does not delete the elements themselves. An Array has a fixed size; therefore, elements cannot be added or removed.

This method is an O(n) operation, where n is length.

Show: