Previous Topic Next topic Print topic


Indexers

Indexers resemble properties except that their accessors take parameters. Indexers allow instances of a class or valuetype to be indexed just like arrays.

indexer-specification

indexer-header procedure-division-header access-modifier statement-block access-modifier statement-block

indexer-header

type-specifier access-modifier attribute-clause

Example

In the following example, a class is defined and provided with simple getter and setters as a means of assigning and retrieving values. Square brackets used to access arrays, use 0-based indexing. Round brackets use 1-based indexing.

       class-id SimpleIndexer.
       01 myArray string occurs 100.

       indexer-id string.
       procedure division using by value i as binary-long.
       getter.
           set property-value to myArray[i]
       setter.
           set myArray[i] to property-value
       end indexer.

       end class.

See also the IndexerDemo.cbl in the Properties sample, available from Start > All Programs > Micro Focus Studio Enterprise Edition x.x > Samples, under COBOL for .NET .

Previous Topic Next topic Print topic