C# Array SetValue(Object, Int32[]) Array
Description
Array SetValue(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.
Syntax
Array.SetValue(Object, Int32[])
has the following syntax.
public void SetValue(
Object value,
params int[] indices
)
Parameters
Array.SetValue(Object, Int32[])
has the following parameters.
value
- The new value for the specified element.indices
- A one-dimensional array of 32-bit integers that represent the indexes specifying the position of the element to set.
Returns
Array.SetValue(Object, Int32[])
method returns
Example
The following code example demonstrates how to set and get a specific value in a one-dimensional or multidimensional array.
using System;/*from w w w . ja v a 2 s . co m*/
public class SamplesArray {
public static void Main() {
String[] myArr1 = new String[5];
String[,,,,,,] myArr7 = new String[5,5,5,5,5,5,5];
// Sets the element at index 1,2,3,0,1,2,3.
int[] myIndices = new int[7] { 1, 2, 3, 0, 1, 2, 3 };
myArr7.SetValue( "one-two-three-zero-one-two-three", myIndices );
Console.WriteLine( "[1,2,3,0,1,2,3]: {0}", myArr7.GetValue( myIndices ) );
}
}
The code above generates the following result.