ArrayList: Item (get)

Item

Gets the element at the specified index.



 Public Property Get Item(
	  ByVal Index As Long ) As Variant

Parameters

Index
[ByVal] Long. The zero-based index of the element to get.

Return Values

Variant -  The element as the specified index.

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

This example demonstrates how to get an element from an ArrayList

Private Sub Main()
    Dim List As New ArrayList
    Dim Item As Variant
    
    List.AddRange Array("My", "name", "is", "Earl")
    
    Debug.Print "The list contains:"
    Debug.Print vbTab; List(0)
    Debug.Print vbTab; List(1)
    Debug.Print vbTab; List(2)
    Debug.Print vbTab; List(3)
End Sub

' The example produces the following output.
'
'    The list contains:
'        My
'        name
'        is
'        Earl

See Also

Project CorLib Overview

Class ArrayList Overview