VB.Net - Syntax


ArrayList

The default capacity for a new arraylist is 16 elements.

Dim aliArrayListIntegers As New System.Collections.ArrayList 

You should always try and define an initial capacity for your arraylist if possible.
This defines an arraylist with an initial capacity of 200 elements.

Dim aliArrayListIntegers  As New System.Collections.ArrayList(200) 

It is possible to initialise an arraylist and to populate it with an initial value.

Dim aliArrayListIntegers  As New System.Collections.ArrayList.Repeat(-1,200) 
Dim alsArrayListStrings As New System.Collections.ArrayList.Repeat("",200)

This method is very concise but not very efficient.
You can also use the contain method.

Do While alsArrayListStrings.IndexOf("remove this") >= 0 
   alsArrayListStrings.Remove("remove this")
Loop


This is far more efficient, this loops until the count property becomes constant.

Dim isavecount As Integer 
Do
   isavecount = alsArrayListStrings.Count
   alsArrayListStrings.Remove("remove this")
Loop While (alsArrayListStrings.Count < isavecount)


Dim arValues() As String 
Dim arArrayList As System.Collections.ArrayList

arValues = DirectCast(arArrayList.ToArray(GetType(String)),String())


© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext