C# Array SetValue(Object, Int32, Int32)

Description

Array SetValue(Object, Int32, Int32) sets a value to the element at the specified position in the two-dimensional Array. The indexes are specified as 32-bit integers.

Syntax

Array.SetValue(Object, Int32, Int32) has the following syntax.


public void SetValue(
  Object value,//  w ww . ja  v  a 2  s .co m
  int index1,
  int index2
)

Parameters

Array.SetValue(Object, Int32, Int32) has the following parameters.

  • value - The new value for the specified element.
  • index1 - A 32-bit integer that represents the first-dimension index of the Array element to set.
  • index2 - A 32-bit integer that represents the second-dimension index of the Array element to set.

Returns

Array.SetValue(Object, Int32, 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 ww .  j  a va  2 s .c om

public class SamplesArray  {

   public static void Main()  {
      // Creates and initializes a two-dimensional array.
      String[,] myArr2 = new String[5,5];

      // Sets the element at index 1,3.
      myArr2.SetValue( "one-three", 1, 3 );
      Console.WriteLine( "[1,3]:   {0}", myArr2.GetValue( 1, 3 ) );

   }

}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version