TrimToSize 方法

将容量设置为 ArrayList 对象中的实际元素数。

语法

Object.TrimToSize()

参数 - Object必需。始终为 ArrayList 对象的名称。

注释

以下示例说明了 TrimToSize 方法的用法。

示例 1:

'Create ArrayList Object
Dim Obj
Set Obj = CreateObject("System.Collections.ArrayList")

'Add Elements to the end of ArrayList Object
Dim Index
Index = Obj.Add(10)
Index = Obj.Add(40)
Index = Obj.Add(20)

'Sets the capacity to the actual number of elements in the ArrayList object
Obj.TrimToSize ()
'Output: Internally ArrayList Capacity changed to the actual number of elements in the ArrayList object