Array.value Method
Gets or sets the value of the array element that is stored at the specified index.
Syntax
public anytype value(int index, [anytype arg])
Run On
Called
Parameters
- index
Type: int
The index number of the array element to get or set.
- arg
Type: anytype
The value to assign to the array element at the specified offset; optional.
Return Value
Type: anytype
The value that is stored at the specified offset.
Remarks
The return type is the same as the type of the array.
If an attempt is made to read a value at an index that is beyond the last index that has a value, an exception is thrown.
If a value is written to a nonexistent location, all locations between the previous element and the nonexistent location are filled with default values, and the array is expanded.
Examples
The following example creates an array of integers and then uses the value method to add some values to the array. It then uses the value method to get the values that are stored in the array and test them.
{
int i;
// Create an integer array
Array ia = new Array (Types::Integer);
// Write some elements in it
for (i = 1; i< 10; i++)
{
ia.value(i, i*2);
}
// Check the values
for (i = 1; i< 10; i++)
{
if (ia.value(i) != 2*i)
{
print "Error!";
}
}
pause;
}