Array.SetValue Method (Object, Int32[])
Sets a value to the element at the specified position in the multidimensional Array. The indexes are specified as an array of 32-bit integers.
Assembly: mscorlib (in mscorlib.dll)
Parameters
- value
-
Type:
System.Object
The new value for the specified element.
- indices
-
Type:
System.Int32[]
A one-dimensional array of 32-bit integers that represent the indexes specifying the position of the element to set.
| Exception | Condition |
|---|---|
| ArgumentNullException | indices is null. |
| ArgumentException | The number of dimensions in the current Array is not equal to the number of elements in indices. |
| InvalidCastException | value cannot be cast to the element type of the current Array. |
| IndexOutOfRangeException | Any element in indices is outside the range of valid indexes for the corresponding dimension of the current Array. |
The number of elements in indices must equal the number of dimensions in the Array. All elements in the indices array must collectively specify the position of the desired element in the multidimensional Array.
The GetLowerBound and GetUpperBound methods can determine whether any of the values in the indices array is out of bounds.
For more information about conversions, see Convert.
This method is an O(1) operation.
Note |
|---|
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. |
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
