Mono Class Library: System.Array Overview | Members

System.Array.GetValue Method

Gets the value at the specified position in the current one-dimensional instance. [Edit]

public object GetValue (int index)

Parameters

index
A int that contains the position of the value to get from the current instance. [Edit]

Returns

A object that contains the value at the specified position in the current instance. [Edit]

Exceptions

TypeReason
ArgumentExceptionThe current instance has more than one dimension. [Edit]
IndexOutOfRangeExceptionindex is outside the range of valid indices for the current instance. [Edit]

Remarks

Note: Use the Array.GetLowerBound(int) and Array.GetUpperBound(int) methods to determine whether index is out of bounds.
[Edit]

Example

This example demonstrates the Array.GetValue(Int32[]) method.

C# Example
using System;
public class ArrayGetValueExample {
   public static void Main() {
      String[] strAry = { "one", "two", "three", "four", "five" };
      Console.Write( "The elements of the array are: " );
      for( int i = 0; i < strAry.Length; i++ )
         Console.Write( " '{0}' ", strAry.GetValue( i ) );
   }
}
   

The output is

The elements of the array are: 'one' 'two' 'three' 'four' 'five'

Requirements

Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0