Home > Article > Backend Development > What are the uses of methods and properties of Array class in C#?
The Array class is the base class for all arrays in C#. It is defined in the System namespace.
The following are the methods of the Array class in C#-
Teacher number | Methods and instructions | 1 |
Clear Sets a range of elements in an array to zero, False, or null, depending on the element type. |
---|---|
2 |
Copy(Array, Array, Int32) From the array One element starts by copying a range of elements and pasting them into another array starting from the first element. The length is specified as a 32-bit integer. |
3 |
CopyTo(Array, Int32) Start at the specified target array index , copies all elements of the current one-dimensional array to the specified one-dimensional array. The index is specified as a 32-bit integer. |
4 | GetLength Gets a 32-bit integer representing the length in the specified dimension of the array Number of elements. |
5 |
GetLongLength Gets a 64-bit integer representing the length in the specified dimension of Array Number of elements. |
6 |
GetLowerBound Get the lower bound of the specified dimension in the array. |
7 | GetType strong> Get the Type of the current instance. (Inherited from Object.) |
8 |
GetUpperBound p> Get the specified dimension in the array upper limit. |
9 |
GetValue(Int32) Get the value at the specified position in the one-dimensional array . The index is specified as a 32-bit integer. |
10 |
IndexOf(array, object) Search for the specified object and return the entire The index of the first occurrence in the dimensional array. |
11 |
Reverse(Array) Reverse the order of elements in one dimension Array. |
#The following are the properties of the Array class in C#.
Sr.No | Properties and Description |
---|---|
1 |
IsFixedSize Gets a value indicating whether the array has a fixed size. |
2 |
IsReadOnly Gets a value indicating whether the array is read-only. |
3 |
Length Get a 32-bit integer representing the length of the array in all dimensions The total number of elements. |
4 |
LongLength Get a 64-bit integer representing the total number in all dimensions of the array Elements. |
5 |
Ranking Get the ranking (dimension) of the array. |
Let us see an example of Reverse method to reverse the characters in a character array and find if it is a palindrome -
Let's try the complete example. Here, our string is "Level", which will give the same result when inverted.
using System; namespace Demo { class Program { static void Main(string[] args) { string string1, rev; string1 = "Level"; char[] ch = string1.ToCharArray(); Array.Reverse(ch); rev = new string(ch); bool b = string1.Equals(rev, StringComparison.OrdinalIgnoreCase); if (b == true) { Console.WriteLine("String " + string1 + " is a Palindrome!"); }else { Console.WriteLine("String " + string1 + " is not a Palindrome!"); } Console.Read(); } } }
The above is the detailed content of What are the uses of methods and properties of Array class in C#?. For more information, please follow other related articles on the PHP Chinese website!