Gets the value at the specified position in the current one-dimensional instance.
- index
- A int that contains the position of the value to get from the current instance.
A object that contains the value at the specified position in the current instance.
Type Reason ArgumentException The current instance has more than one dimension. IndexOutOfRangeException index is outside the range of valid indices for the current instance.
Note: Use the Array.GetLowerBound(int) and Array.GetUpperBound(int) methods to determine whether index is out of bounds.
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'
Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0