Access .NET arrays
- Last Updated: April 10, 2024
- 3 minute read
- OpenEdge
- Version 12.8
- Documentation
The first thing to note about accessing .NET arrays is that, by default, .NET array dimensions use zero (0)-based indexing as compared to ABL arrays, which always use one (1)-based indexing.
You can access a .NET array created in the .NET context, like any other .NET object, by using its object reference directly from a .NET class member, or by defining an ABL object reference variable or property and assigning the .NET class member to it.
Using NEW to instantiate a .NET array object in ABL
You can instantiate a .NET
array object in ABL by using the NEW function or
statement. Here is the syntax:
|
- type-name-string
- A fully qualified type name
- dimensions
- Represents one or more parameters that define the dimensions of the array
Here is an example:
|
SetValue( ) instance method
The SetValue( ) instance method stores an object reference
at the specified location in the array, overloaded depending on the number of
dimensions:
|
The array-object-ref is a reference to an array object instance. The element is an ABL primitive value or a reference to an object you want to store as an element of the array. The index-info represents one or more parameters that identify the element location, depending on the array dimensions.
System.Object. So, if element is an ABL
primitive type, and you want to store a .NET mapped data type other than the default match
for that ABL data type, you must specify the AS option with
the AS data type that matches the explicit .NET mapped type
(see Pass ABL data types to .NET constructor and method parameters).GetValue( ) instance method
The GetValue( ) instance method returns an object
reference to the element type from the specified location in the array, overloaded depending
on the number of dimensions and extents:
|
The array-object-ref is a reference to an array object instance. The index-info represents one or more parameters that identify the element location, depending on the defined dimensions of the array and their extents. Typically, you want to cast the return value to the type of object that the array stores.
Item default indexed property
The Item default indexed property, defined as System.Object, provides indexed read and write access to each
element of an array object, similar to how you use a subscript to access an ABL array.
Item is actually an explicit interface member of the
System.Collections.IList interface, which System.Array implements.You can read or write all of the array
elements using the default property indexer directly on the IList object reference, as in the following example:
|
The following example is similar, but defines the variable as
System.String[], which is not an ABL array or an indexed property. You
use SetValue() and GetValue() to set and retrieve the
values instead:
|
For more information on default indexed properties, see Access .NET indexed properties and collections, and for more information on explicit interface members, see Access members of .NET interfaces.
For more .NET information on these methods and other members of System.Array, see the .NET Class Library documentation. For an
on-line reference, see OpenEdge-installed .NET Controls.
For a working example of accessing a .NET array using System.Array mechanisms, see Example: Access a .NET array.