CArray:Init CArray:Remove

CArray:MaxIndex


The MaxIndex method returns the maximum member index in the CArray.

Syntax

number = CArray:MaxIndex()

Remarks

This method returns the maximum member index. Since all indices do not have to be packed in a sparse array, the returned value is not the same as the number of values in the array. This is the same as the number of members needed to hold every possible integral index between 1 and MaxIndex. For example, if the CArray has two members, one at index [1] and the other at index [10000], then MaxIndex = 10000.

Example

Suppose a CArray assigned to A contains 3 members as shown below:

 

A = CMatrix:new()

-- create a CMatrix

A:Set( 2, 1805 )

-- set member [2]

A:Set( 50, 102 )

-- set member [50]

A:Set( 120, 600.5 )

-- set member [120]

Printf("N = %d", A:MaxIndex() )

-- result: N = 120

A:delete()

-- if finished with A, clean up memory

Related Topics

CArray, Exists