ArrayListLib interfaces
The package declares nine interfaces. Six have the name and the role of an interface of .NET: ICloneable, ICollection, IComparer, IEnumerable, IEnumerator and IList. IListRange and IArrayList are the package’s own, and IEnumVARIANT is the interface of COM that For Each uses. Each one adds members to the one it extends:
IEnumerable
ICollection
IList
IListRange
IArrayList (also implements ICloneable)
IEnumVARIANT
IEnumerator
IComparer
ArrayList and ListRange implement IArrayList, so a variable of any of these types can hold a list. A function that only reads items can take an IList; a function that sorts or takes parts can take an IListRange. Enumerator implements IEnumerator, and Comparer implements IComparer.
Dim items As IList = New ArrayList
items.Add "a"
items.Add "b"
Debug.Print items.Count
Debug.Print items.Item(1)
Dim v As Variant
For Each v In items
Debug.Print v
Next
The members of the interfaces that a list implements are described once, on the page of ArrayList; the entries below give the syntax and point there.
- IEnumerable
- ICollection
- IList
- IListRange
- IArrayList
- ICloneable
- IEnumVARIANT
- IEnumerator
- IComparer
- See Also
IEnumerable
The base of the list interfaces: an object that For Each can go through. Interface identifier F078EB73-3FA5-47F4-8003-520AEA1CE315.
GetEnumerator
Returns the enumerator that For Each uses.
Syntax: object.GetEnumerator ( [ Index ] [ , GetCount ] [ , GetStep ] [ , ThisEnumerator ] ) As stdole.IUnknown
The member is marked [Enumerator]. The parameters are those of GetEnumerator of ArrayList; here ThisEnumerator is declared As Any, an untyped reference.
ICollection
Extends IEnumerable. The base interface of all collections. Interface identifier B2E5C8F5-2847-450B-873B-F4BE7621F627.
Count
The number of items. Long, read-only.
Syntax: object.Count
See Count.
CopyTo
Copies the items to an array or over the items of another list.
Syntax: object.CopyTo ( Target, Index )
See CopyTo.
IsSynchronized
Whether access to the collection is safe from several threads. Boolean, read-only. Always False in the package.
Syntax: object.IsSynchronized
SyncRoot
An object to lock for access from several threads. Variant, read-only. Always Nothing in the package.
Syntax: object.SyncRoot
IList
Extends ICollection. The base interface of all lists. Interface identifier BC694131-C923-4813-9D34-C79C5E2F6980.
Add
Adds an item at the end of the list and returns its index.
Syntax: object.Add ( Value ) As Long
See Add.
Clear
Removes all items.
Syntax: object.Clear ( )
See Clear.
Contains
Returns whether the list holds an item that matches a value.
Syntax: object.Contains ( Value ) As Boolean
See Contains.
IndexOf
Returns the index of the first item that matches a value, or -1.
Syntax: object.IndexOf ( Value [ , Index [ , GetCount ] ] ) As Long
See IndexOf.
Insert
Inserts an item at a position.
Syntax: object.Insert ( Index, Value )
See Insert.
IsFixedSize
Whether the list has a fixed size. Boolean, read-only. Always False in the package.
Syntax: object.IsFixedSize
IsReadOnly
Whether the list cannot be changed. Boolean, read-only. Always False in the package.
Syntax: object.IsReadOnly
Item
The item at a position. Variant, read/write.
Syntax: [ Set ] object.Item ( Index ) [ = Value ]
See Item. The interface does not mark Item as the default member; the classes do.
Remove
Removes the first item that matches a value.
Syntax: object.Remove ( Value )
See Remove.
RemoveAt
Removes the item at a position.
Syntax: object.RemoveAt ( Index )
See RemoveAt.
IListRange
Extends IList. A list with operations on runs of items. It is the type that GetRange returns. Interface identifier 480A22F9-91B0-483A-8A33-11634FCF644A.
AddRange
Adds the items of an array or collection at the end.
Syntax: object.AddRange ( Target )
See AddRange.
BinarySearch
Searches a sorted run of items.
Syntax: object.BinarySearch ( Index, GetCount, Value [ , Comparer ] ) As Long
See BinarySearch.
GetAddressOfItemAt
Returns the address in memory of an item. Hidden.
Syntax: object.GetAddressOfItemAt ( Index ) As LongPtr
The package uses it to copy runs of items between lists. The address stays valid only until the list changes, and a program has no use for it.
GetRange
Returns a view of a run of items.
Syntax: object.GetRange ( Index, GetCount ) As IListRange
See GetRange.
InsertRange
Inserts the items of an array or collection at a position.
Syntax: object.InsertRange ( Index, Target )
See InsertRange.
RemoveRange
Removes a run of items.
Syntax: object.RemoveRange ( Index, GetCount )
See RemoveRange.
SetRange
Replaces items with the items of an array or collection.
Syntax: object.SetRange ( Index, Target )
See SetRange.
Sort
Sorts the items, or a run of them.
Syntax: object.Sort ( [ Index ] [ , GetCount ] [ , Comparer ] )
See Sort.
ToArray
Returns the items as an array.
Syntax: object.ToArray ( ) As Variant()
See ToArray.
IArrayList
Extends IListRange and implements ICloneable. The interface of a whole list. Interface identifier 1043D433-27BB-40F7-9255-50F4724FAB94.
Capacity
The number of items the list has room for. Long, read/write.
Syntax: object.Capacity [ = value ]
See Capacity.
Clone
Returns a copy of the list.
Syntax: object.Clone ( ) As Variant
The member of ICloneable again; see Clone.
CloneTo
Fills the list with copies of items of another list. Hidden.
Syntax: object.CloneTo ( Target, Source, Index, GetCount )
Clone calls it on the new list. The list it is called on takes copies of GetCount items of Source, from Index. Target is not used.
Items
Returns the items as an array that shares the memory of the list. Hidden.
Syntax: object.Items ( ) As Variant()
See Items.
LastIndexOf
Returns the index of the last item that matches a value, or -1.
Syntax: object.LastIndexOf ( Value [ , Index [ , GetCount ] ] ) As Long
See LastIndexOf.
Reverse
Reverses the order of the items, or of a run of them.
Syntax: object.Reverse ( [ Index ] [ , GetCount ] )
See Reverse.
Version
A number that changes each time the list changes. Long, read-only. Hidden.
Syntax: object.Version
See Version.
ICloneable
An object that can make a copy of itself. IArrayList implements it. Interface identifier 8ABD76D4-42F5-4920-927A-BC766E00CE46.
Clone
Returns a copy of the object. Whether the copy is shallow or deep is up to the class.
Syntax: object.Clone ( ) As Variant
IEnumVARIANT
The interface that For Each calls to go through the items of an object, one at a time. The package declares it as a public interface, with Long counts, because the declaration in stdole cannot be implemented in twinBASIC. Interface identifier 00020404-0000-0000-C000-000000000046. See IEnumVARIANT for the contract of the four methods, and Enumerator for the class that implements them.
Clone
Creates another enumerator over the same items.
Syntax: object.Clone ( ppenum )
- ppenum
- required An IEnumVARIANT variable that receives the new enumerator.
Next
Returns the next item.
Syntax: object.Next ( celt, rgvar, pceltFetched )
- celt
- required A Long: the number of items asked for.
- rgvar
- required A Variant that receives the item.
- pceltFetched
- required A Long that receives the number of items returned.
Reset
Goes back to the first item.
Syntax: object.Reset ( )
Skip
Moves past items without returning them.
Syntax: object.Skip ( celt )
- celt
- required A Long: the number of items to move past.
IEnumerator
Extends IEnumVARIANT. An enumerator whose position, step and size can be read and changed. Interface identifier 8E42D737-24C2-4D3F-8903-4B30E9383C69. It is the type of the ThisEnumerator argument of GetEnumerator.
CurrentIndex
The position of the item last returned. Long, read/write.
Syntax: object.CurrentIndex [ = value ]
See CurrentIndex.
CurrentSize
The number of items in the part that is enumerated. Long, read/write.
Syntax: object.CurrentSize [ = value ]
See CurrentSize.
CurrentStep
How far the position moves for each item. Long, read/write.
Syntax: object.CurrentStep [ = value ]
See CurrentStep.
IComparer
An object that compares two values. Sort and BinarySearch take one. A class implements it with Implements IComparer, as the examples on the page of Comparer show. Interface identifier D60ABA2A-1176-4515-9B4C-B0312BA5FE7F.
Compare
Compares two values.
Syntax: object.Compare ( X, Y ) As Long
- X
- required The first value.
- Y
- required The second value.
Returns a negative number when X goes before Y, 0 when they are equal and a positive number when X goes after Y. Only the sign of the number matters to the list.
See Also
- ArrayList class – implements IArrayList
- ListRange class – implements IArrayList over a run of a list
- Enumerator class – implements IEnumerator
- Comparer class – implements IComparer
- ArrayListLib package – overview