Gets the value at the specified position in the one-dimensional Array. The index is specified as a 32-bit integer.
- index
- A 32-bit integer that represents the position of the Array element to get.
The value at the specified position in the one-dimensional Array.
Type Reason ArgumentException The current instance has more than one dimension. IndexOutOfRangeException index is outside the range of valid indices for the current instance.
The Array.GetLowerBound(int) and Array.GetUpperBound(int) methods can determine whether the value of index is out of bounds.
This method is an O(1) operation.
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'