The Array class is the base class for all the arrays in C#. It is defined in the System namespace.The most commonly used methods of the array class are −
| Sr.No. | Methods & Description |
|---|---|
| 1 | Clear Sets a range of elements in the Array to zero, to false, or to null, depending on the element type |
| 2 | Copy(Array, Array, Int32) Copies a range of elements from an Array starting at the first element and pastes them into another Array starting at the first element. The length is specified as a 32-bit integer. |
| 3 | CopyTo(Array, Int32) Copies all the elements of the current one-dimensional Array to the specified one-dimensional Array starting at the specified destination Array index. The index is specified as a 32-bit integer. |
| 4 | GetLength Gets a 32-bit integer that represents the number of elements in the specified dimension of the Array. |
| 5 | GetLongLength Gets a 64-bit integer that represents the number of elements in the specified dimension of the Array |
| 6 | GetLowerBound Gets the lower bound of the specified dimension in the Array. |
| 7 | GetType Gets the Type of the current instance. (Inherited from Object.) |
| 8 | GetUpperBound Gets the upper bound of the specified dimension in the Array. |
Let us see an eample to get the Upperbound as well Lowerbound of an array using Array class methods −
Example
using System;
class Program {
static void Main() {
int[,] arr = new int[3,4];
Console.WriteLine(arr.GetLength(0));
Console.WriteLine(arr.GetLength(1));
// Length
Console.WriteLine(arr.Length);
Console.WriteLine("Upper Bound: {0}",arr.GetUpperBound(0).ToString());
Console.WriteLine("Lower Bound: {0}",arr.GetLowerBound(0).ToString());
}
}Output
3 4 12 Upper Bound: 2 Lower Bound: 0