Array.SetValue Method (Object, Int64, Int64)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Sets a value to the element at the specified position in the two-dimensional Array. The indexes are specified as 64-bit integers.

Namespace:   System
Assembly:  mscorlib (in mscorlib.dll)

member SetValue : 
        value:Object *
        index1:int64 *
        index2:int64 -> unit


Type: System.Object

The new value for the specified element.

Type: System.Int64

A 64-bit integer that represents the first-dimension index of the Array element to set.

Type: System.Int64

A 64-bit integer that represents the second-dimension index of the Array element to set.

Exception Condition

The current Array does not have exactly two dimensions.


value cannot be cast to the element type of the current Array.


Either index1 or index2 is outside the range of valid indexes for the corresponding dimension of the current Array.

The GetLowerBound and GetUpperBound methods can determine whether any of the indexes is out of bounds.

For more information about conversions, see Convert.

This method is an O(1) operation.


If SetValue is used to assign null to an element of an array of value types, all fields of the element are initialized to zero. The value of the element is not a null reference, and cannot be found by searching for a null reference.

The following code example demonstrates how to set and get a specific value in a one-dimensional or multidimensional array.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 1.1
Return to top