System Namespace Array Class
Sets the specified element in the current Array to the specified value.
Sets a value to the element at the specified position in the one-dimensional Array.
Sets a value to the element at the specified position in the multidimensional Array.
Sets a value to the element at the specified position in the two-dimensional Array.
Sets a value to the element at the specified position in the three-dimensional Array.
The following code example shows how to use SetValue to initialize an Array.
NOTE: This example shows how to use one of the overloaded versions of SetValue. For other examples that might be available, see the individual overload topics.
[ VB ]
Imports System
Imports Microsoft.VisualBasic
Public Class SamplesArray
Public Shared Sub Main ( )
' Creates and initializes a new Array.
Dim myArray As Array = Array.CreateInstance ( GetType ( String ) , 2, 4 )
myArray.SetValue ( "The", 0, 0 )
myArray.SetValue ( "quick", 0, 1 )
myArray.SetValue ( "brown", 0, 2 )
myArray.SetValue ( "fox", 0, 3 )
myArray.SetValue ( "jumped", 1, 0 )
myArray.SetValue ( "over", 1, 1 )
myArray.SetValue ( "the", 1, 2 )
myArray.SetValue ( "lazy", 1, 3 )
' Displays the values of the Array.
Response.WriteLine ( "The Array contains the following values:" )
Dim i, j As Integer
For i = myArray.GetLowerBound ( 0 ) To myArray.GetUpperBound ( 0 )
For j = myArray.GetLowerBound ( 1 ) To myArray.GetUpperBound ( 1 )
Response.WriteLine ( ControlChars.Tab + "[{0},{1}]:" _
+ ControlChars.Tab + "{2}", i, j, myArray.GetValue ( i, j ) )
Next j
Next i
End Sub
End Class
' This code produces the following output.
'
' The Array contains the following values:
' [0,0]: The
' [0,1]: quick
' [0,2]: brown
' [0,3]: fox
' [1,0]: jumped
' [1,1]: over
' [1,2]: the
' [1,3]: lazy
[ C# ]
using System;
public class SamplesArray {
public static void Main ( ) {
// Creates and initializes a new Array.
Array myArray=Array.CreateInstance ( typeof ( String ) , 2, 4 );
myArray.SetValue ( "The", 0, 0 );
myArray.SetValue ( "quick", 0, 1 );
myArray.SetValue ( "brown", 0, 2 );
myArray.SetValue ( "fox", 0, 3 );
myArray.SetValue ( "jumped", 1, 0 );
myArray.SetValue ( "over", 1, 1 );
myArray.SetValue ( "the", 1, 2 );
myArray.SetValue ( "lazy", 1, 3 );
// Displays the values of the Array.
Response.WriteLine ( "The Array contains the following values:" );
for ( int i = myArray.GetLowerBound ( 0 ); i <= myArray.GetUpperBound ( 0 ); i++ )
for ( int j = myArray.GetLowerBound ( 1 ); j <= myArray.GetUpperBound ( 1 ); j++ )
Response.WriteLine ( "\t[{0},{1}]:\t{2}", i, j, myArray.GetValue ( i, j ) );
}
}
/*
This code produces the following output.
The Array contains the following values:
[0,0]: The
[0,1]: quick
[0,2]: brown
[0,3]: fox
[1,0]: jumped
[1,1]: over
[1,2]: the
[1,3]: lazy
*/
[JScript ]
import System;
// Creates and initializes a new Array.
var myArray : System.Array = System.Array.CreateInstance ( System.String, 2, 4 );
myArray.SetValue ( "The", 0, 0 );
myArray.SetValue ( "quick", 0, 1 );
myArray.SetValue ( "brown", 0, 2 );
myArray.SetValue ( "fox", 0, 3 );
myArray.SetValue ( "jumped", 1, 0 );
myArray.SetValue ( "over", 1, 1 );
myArray.SetValue ( "the", 1, 2 );
myArray.SetValue ( "lazy", 1, 3 );
// Displays the values of the Array.
Response.WriteLine ( "The Array contains the following values:" );
for ( var i : int = myArray.GetLowerBound ( 0 ); i <= myArray.GetUpperBound ( 0 ); i++ )
for ( var j : int = myArray.GetLowerBound ( 1 ); j <= myArray.GetUpperBound ( 1 ); j++ )
Response.WriteLine ( "\t[{0},{1}]:\t{2}", i, j, myArray.GetValue ( i, j ) );
/*
This code produces the following output.
The Array contains the following values:
[0,0]: The
[0,1]: quick
[0,2]: brown
[0,3]: fox
[1,0]: jumped
[1,1]: over
[1,2]: the
[1,3]: lazy
*/
Array Members