Introduction
C# is a multi-paradigm, general programming language. C# was designed by Anders Hejlsberg in 2000. Later it was introduced by Microsoft along with the .NET framework and Visual Studio.
The array is nothing but a collection of elements of a similar data type. Each element stored in an array can be accessed easily using only the index of the element. The Array Class in C# is used to manipulate data present in an array. Developers can reverse, sort, clone, empty, and perform many more functions on an array using the Array Class.
Methods
There are various methods present in the Array Class that can be used to work on arrays. Let us look at some of these methods,
- AsReadOnly(): This method is used to return a read-only wrapper for a given array.
- Clear(): The Clear method is used to a set of elements in an array.
- BinarySearch(): The BinarySearch method is used to perform a binary search on a one-dimensional array.
- Clone(): This method can be used to create a copy of a given array.
- ConvertAll(): This method is used to convert an array from one data type to an array with a different data type.
- Copy(): The Copy method is used to copy all the values from one array to another.
- CreateInstance(): This method is used to create an instance of the Array Class.
- Empty(): This method returns an empty array.
- Find(): This method returns the first occurrence of the specified element in an array.
- FindAll(): This method returns all the occurrences of the specified element in an array.
- FindIndex(): This method returns the index of the first occurrence of the specified element in an array.
- FindLastIndex(): This method returns the index of the last occurrence of the specified element in an array.
- ForEach(): This method is used to iterate through all the elements present in an array.
- GetHashCode(): This method is used as a default hash function for arrays.
- Reverse(): This method is used to reverse the value of a one-dimensional array.
- Sort(): The sort method is used to sort all the values in an array.
- TrueForAll(): This method determines if all the elements present in the array satisfy the specified condition.