ArrayList: Item (set)

Item

Sets the element at the specified index.



 Public Property Set Item(
	  ByVal Index As Long,
	  ByRef Value As Variant )

Parameters

Index
[ByVal] Long. The zero-based index in the list to set the value.
Value
[ByRef] Variant. The value to set in the list.

Remarks

ArrayList accepts allows duplicate elements.

This property provides the ability to access a specific element in the collection by using the following syntax: MyCollection(index).

ArrayList implements Item as the default property.

Retrieving the value of this property is an O(1) operation; setting the property is also an O(1) operation.

Read/Write.

Exceptions

ExceptionCondition
ArgumentOutOfRangeException Index is less than zero.
-or-
Index is equal to or greater than Count.

Examples

The example demonstrates how to directly set a value in an ArrayList.

Private Sub Main()
    Dim List As New ArrayList
    Dim Item As Variant
    
    List.AddRange Array("My", "name", "is", "Earl")
    
    Debug.Print "Original list contents."
    PrintValues List
    Debug.Print
    
    List(2) = "isn't"
    
    Debug.Print "Updated list contents."
    PrintValues List
End Sub

Private Sub PrintValues(ByVal List As IEnumerable)
    Dim Value As Variant
    
    For Each Value In List
        Debug.Print Value & " ";
    Next
    
    Debug.Print
End Sub

' The example produces the following output.
'    Original list contents.
'    My Name Is Earl
'
'    Updated list contents.
'    My name isn't Earl

See Also

Project CorLib Overview

Class ArrayList Overview