VOOZH about

URL: https://www.geeksforgeeks.org/c-sharp/array-class-in-c-sharp/

⇱ Array Class in C# - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Array Class in C#

Last Updated : 9 Sep, 2025

The Array class in C# (defined in the System namespace) provides methods and properties to work with arrays. Unlike simple array declarations, the Array class gives built in functionality to manipulate arrays (sorting, searching, copying, etc.).

Example: Using Array Class

Array Class Characteristics

  • The length of the array is the number of elements it holds.
  • The lower bound of an Array is the index of its first element and the default value of the lower bound is 0.
  • The default size of an Array is 2GB.
  • Arrays of the same type share the same type or Class object.

Array Traversal

Example: This example demonstrates array traversal.


Output
Array elements are:
10
20
30
40
50

Array Class Properties

The Array class provides several properties to access its state.

PropertiesDescription
IsFixedSizeIndicates whether the array has a fixed size (always true for arrays).
IsReadOnlyIndicates whether the array is read-only.
IsSynchronizedIndicates whether access to the array is thread-safe.
LengthGets the total number of elements in all dimensions.
LongLengthGets the total number of elements as a 64-bit integer.
RankGets the number of dimensions of the array.

SyncRoot

Gets an object that can be used to synchronize access (for thread safety).

Example 1: Length property


Output
Length of the array: 6

Example 2: Rank property


Output
Rank of the array: 1
10
20
30
40
50
60

Methods

MethodDescription
AsReadOnly()Returns a read-only wrapper for the specified array.
BinarySearch()Searches a sorted one-dimensional array using binary search.
Clear()Sets elements in a range to their default values.
Clone()Creates a shallow copy of the array.
ConstrainedCopy()Copies a range of elements with rollback if the copy fails.
ConvertAll()Converts an array of one type to another type.
Copy()Copies elements from one array to another (with type casting if needed).
CopyTo()Copies all elements to another one-dimensional array.
CreateInstance()Creates a new instance of the Array class.
Empty()Returns an empty array of a specified type.
Equals()Checks if two arrays are equal.
Exists()Checks if any element matches a given condition.
Find()Returns the first element that matches a condition.
FindAll()Returns all elements that match a condition.
FindIndex()Returns the index of the first element that matches a condition.
FindLast()Returns the last element that matches a condition.
FindLastIndex()Returns the index of the last element that matches a condition.
ForEach()Performs an action on each element of the array.
GetEnumerator()Returns an IEnumerator for the Array.
GetHashCode()Returns the hash code for the array.
GetLength()Gets the number of elements in a specified dimension (32-bit).
GetLongLength()Gets the number of elements in a specified dimension (64-bit).
GetLowerBound()Gets the index of the first element of a dimension.
GetType() Gets the runtime type of the array.
GetUpperBound()Gets the index of the last element of a dimension.
GetValue()Gets the value of the specified element in the current Array.
IndexOf()Returns the index of the first occurrence of a value.
Initialize()Initializes each element of a value-type array.
LastIndexOf()Returns the index of the last occurrence of a value.
MemberwiseClone()Creates a shallow copy of the object.
Resize() Resizes a one-dimensional array to the specified size.
Reverse() Reverses the order of elements in an array.
SetValue() Sets the value of an element at a specified index.
Sort()Sorts the elements in a one-dimensional array.
ToString()Returns a string representation of the array (inherited from Object).
TrueForAll()Checks if all elements match a specified condition.

Example 1: Array.Reverse()


Output
Array before reverse:
10 20 30 40 50 60 
Array after reverse:
60 50 40 30 20 10 

Example 2: Array.sort()


Output
Array before sorting:
50 20 40 10 60 30 
Array after sorting:
10 20 30 40 50 60 
Comment
Article Tags:
Article Tags:

Explore