System.Collections.ArrayList

WTSupported in traditional Synergy on Windows
WNSupported in Synergy .NET on Windows
USupported on UNIX
VSupported on OpenVMS
namespace System.Collections
public class ArrayList

The System.Collections.ArrayList class is a dynamic collection class with 0-based indexing (which means the index of the first element is 0). See "Variable references" in the Basic language elements topic for more information about array references.

Constructors

ArrayList

public ArrayList()

Initializes a new instance of ArrayList with a default capacity of 16 elements.

or

public ArrayList(capacity)

Initializes a new instance of ArrayList with the specified initial capacity (int), which is the number of elements the new array list can store.

Properties

Capacity

public virtual Capacity

Returns or sets the number of elements that the array list can contain. (int)

Count

public virtual Count

Returns the number of elements that are actually in the array list. (int)

Indexer

public virtual Indexer(index)

Returns the element in the array that is located at the index (0-based, int). (@*)

Methods

Add

public virtual Add(object), int

Adds the specified element to the end of an array list and returns the array list index at which object has been added. Object can be null. (@*)

Clear

public virtual Clear(), void

Removes all elements from the array list. Sets count to zero and releases references to other objects.

Clone

public virtual Clone(), @Object

Returns a new array list that is a shallow copy of objects in the current array list. A shallow copy includes only the elements in the array list (not the objects that any references refer to).

IndexOf

IndexOf() determines equality by calling the Equals() method of the ArrayList element type.

public virtual IndexOf(object), int

Returns the first 0-based index position for the specified object in the entire array list. Object can be null. (@*)

or

public virtual IndexOf(object, startindex), int

Returns the first 0-based index position for the specified object (@*) within the range of elements between startindex (int) and the last element. Object can be null.

or

public virtual IndexOf(object, startindex, count), int

Returns the first 0-based index position for the specified object (@*) within the range of elements starting at startindex (int) and continuing for the number of elements specified in count (int).

Insert

public virtual Insert(index, object), void

Inserts an element (@*) into the array list at the specified 0-based index (int). Object can be null.

LastIndexOf

LastIndexOf() determines equality by calling the Equals() method of the ArrayList element type.

public virtual LastIndexOf(object), int

Returns the last 0-based index position for the specified object (@*) in the entire array list. Object can be null.

or

public virtual LastIndexOf(object, startindex), int

Returns the last 0-based index position for the specified object (@*) within the range of elements between the first element and startindex (int). Object can be null.

or

public virtual LastIndexOf(object, startindex, count), int

Returns the last 0-based index position for the specified object within the range that contains count elements (int) and ends at startindex (int). In other words, it counts backwards from startindex for the number of elements specified in count. Object can be null. (@*)

RemoveAt

public virtual RemoveAt(index), void

Removes the element at the specified 0-based index (int). The elements that follow are moved up to occupy the vacant spot.

Examples

import System.Collections

structure syntxtrec
    recdata        ,a218
endstructure

main

proc
    begin
      ;Declare variable as ArrayList
      data al               ,@ArrayList
      data fchn      ,int
      data ttchn     ,int
      data counter   ,int
      data numrecs   ,int
      ;Structfield based on structure syntxtrec
      data sf              ,syntxtrec
      ;Object type of structfield
      data sfO             ,@syntxtrec

      open(fchn =%syn_freechn, I:I, "DBLDIR:syntxt.ism")
      open(ttchn=%syn_freechn, O, "TT:")

      ;Get the number of records in the syntxt ISAM file
      numrecs = %isinfo(fchn, "NUMRECS")
 
      ;Create arraylist with capacity of number of records in syntxt
      al = new arraylist(numrecs)

      ;Populate the ArrayList with records from the syntxt ISAM file
      for counter from 0 thru numrecs - 1
        begin
          reads(fchn, sf, eof)
          ;Must cast as structfield object to add structfield to arraylist
          ;as ArrayList may only contain objects
          al.Add((@syntxtrec)sf)
        end

eof,
    foreach sfO in al              ;Must use object type to iterate through ArrayList in foreach loop
      begin
        writes(ttchn, %atrim(sfO)) ;Write out value
      end

      ;Clean up
      al = ^NULL
      close fchn, ttchn
    end
endmain