asp.net.ph

Array.GetValue Method

System Namespace   Array Class


Returns the value of the specified element in the current Array.

Overload List

1. Gets the value at the specified position in the one-dimensional Array.

2. Gets the value at the specified position in the multidimensional Array.

3. Gets the value at the specified position in the two-dimensional Array.

4. Gets the value at the specified position in the three-dimensional Array.


Example

The following code example shows how to use GetValue to get a specific value in the Array.

NOTE: This example shows how to use one of the overloaded versions of GetValue. 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
 */ 
See Also

Array Members Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph