Rubén Aroca Rubén Aroca - 1 year ago 83 Question

Set a fixed size ArrayList

someone knows if it's possible create a fixed size ArrayList? Or I have to use necessarily an array?

I try with this

Dim array As ArrayList

array = New ArrayList(10)


array.Capacity = 10

But I can add more than 10 items, and it doesn 't show me any kind of error how I expected.


Answer Source

Just use an Array this size will not change unless you explicitly code it to.

Dim myArray(9) As String 'or whatever object you need Integer, etc.

Note that specifying 9 will create 0-9 i.e. 10 items in your array

(ArrayLists are bad in many many ways so don't use them)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download