Share via


Array.value Method

Definition

Overloads

value(Int32)

Gets or sets the value of the array element that is stored at the specified index.

value(Int32, Object)

value(Int32)

Gets or sets the value of the array element that is stored at the specified index.

public:
 System::Object ^ value(int _index);
public object value (int _index);
member this.value : int -> obj
Public Function value (_index As Integer) As Object

Parameters

_index
Int32

The value to assign to the array element at the specified offset; optional.

Returns

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.

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; 
}

Applies to

value(Int32, Object)

public:
 System::Object ^ value(int _index, System::Object ^ _arg);
public object value (int _index, object _arg);
member this.value : int * obj -> obj
Public Function value (_index As Integer, _arg As Object) As Object

Parameters

_index
Int32
_arg
Object

The value to assign to the array element at the specified offset; optional.

Returns

Applies to