ArrayIterator

ArrayIterator inherits Iterator

ArrayIterator is a type that allows the user to iterate over a range of elements in an Array container. Use the GetIterator method to obtain an iterator to the beginning of the array.

Usage:

Array<double> array = Array<double>();
ArrayIterator iter = array.GetIterator();
while (iter.HasNext())
{
   iter.Next();
   int index = (int)iter.Key();
   double data = (double)iter.Data();
}

When iterating over the entire range of the Array, the foreach loop is a more convenient method:

Array<double> array = Array<double>();
foreach (double data in array) // Only data is needed
{
   ...
}

foreach (int index : double data in array) // Both index and data are needed
{
   ...
}

Methods

Note

Return values from methods that return Object should be cast to the correct key and data types.

bool HasPrev()

Returns true if another element exists before the current element.

Object Prev()

Decrements the iterator to the previous element and returns its associated data, which should be cast to the data type of the Array before usage. If at the beginning of the array and no previous element exists, invalid data is returned, so HasPrev() should be queried before using this method.

Object Key()

Returns the index associated with the current element, in the range [0, Size() - 1]. Should be cast to int before usage.

Object Data()

Returns the data associated with the current element, which should be cast to the data type of the Array before usage.

See Iterator for a list of methods inherited by all iterator types.