Default indexed properties
- Last Updated: January 17, 2024
- 2 minute read
- OpenEdge
- Version 12.8
- Documentation
Default indexed properties
A .NET class can have one default indexed
property. In fact, C# can only define default indexed properties.
The default indexed property for a class typically has the name, Item. ABL
allows you to access a default indexed property in two ways:
- Using the indexer on the property name, as described previously
- Using the indexer directly on the object reference to a class instance without the need to specify the property name, as in the following syntax:
|
For example, the following code
fragment displays the same default indexed property value of a System.Windows.Forms.Control+ControlCollection object
by using the indexer on the object reference and by using its property
name:
|
Progress.Windows.Form is
an OpenEdge .NET form class that inherits from System.Windows.Forms.Form.
For more information, see Create and use forms and controls.The Controls property
of a .NET form is defined as a Control+ControlCollection object
and is an example of a .NET collection. All collections have
a default indexed property, along with common properties and methods
to access the objects that they contain. In this fragment, the Add( ) method
is used to add objects to the collection. For more information on
using collections, see Work with collections.
Note that sometimes a property
is defined as a class type, and this class type has a default indexed
property as a member. For such properties, references to the default
indexed property of the class type make the property, itself, appear to
be an indexed property. For example, the Controls property
on a System.Windows.Forms.Form class is defined
as a System.Windows.Forms.Form+ControlCollection,
whose control instances you can access:
|
So, when you reference the Controls property
to access one of the control instances that the class it references
contains, the Controls property reference, itself,
appears to be a reference to a non-default indexed property on its
class instance (rControl). Instead, you are actually
using a non-indexed property (Controls) to reference
the default indexed property on the class instance (Form+ControlCollection)
that the Controls property, itself, references.
In ABL, the two different references—a non-default indexed property
reference and a non-indexed property reference to a default indexed
property—appear syntactically the same, but they refer to two different
things, which you typically do not have to recognize when using
them.