Array----how to clear it

It is actually impossible to clear an array of elements. Once you create an array with a specific number of elements that array object always has that number of elements. What the Array.Clear method does is reset those elements to their default values. That means that if each element is a value type, like an Integer, Boolean, DateTime, etc., then each element will be 0, False, #1/01/0001#, etc. If each element is a reference type then they will all be null references. Think of an array like an egg carton. Even if you remove all the eggs the 12 cups are still sitting there.

If that is what you want then Array.Clear is for you. If you genuinely want to be able to have an array with zero elements then you should use a collection instead, like an ArrayList. A collection allows you to dynamically add and remove items, so when you call a collections Clear method its Count property will then return zero.
 
Back
Top