C# Array Class4 min read

There are various operations that can be done with an array such as creating, manipulating, sorting, searching, etc. This is done by the array class that provides various methods to perform mentioned operation in C#.

Note: In C#, Array is not part of the collection but considered as a collection because it is based on the IList interface.


Properties of the Array Class – C#

The following table represents some of the properties of the Array class that are mostly used.

PropertyDescription
IsFixedSizeThis property is used to get a value indicating whether the Array has a fixed size or not.
IsReadOnlyThis is used to check whether the Array is read-only or not.
LengthThis property gets (32-bit integer) that represents the total number of elements in all the dimensions of the Array.
LongLengthThis property gets (a 64-bit integer) that represents the total number of elements in all the dimensions of the Array.
RankThis property gets the rank (number of dimensions) of the Array.
SyncRootIt gets an object that can be used to synchronize access to the Array.
IsSynchronizedIt checks whether the access to the Array is synchronized.

Methods of the Array Class – C#

The following table represents some of the methods of the Array class that are mostly used.

MethodDescription
BinarySearch()This method is used to search an entire one-dimensional sorted array for a specific value. It uses binary search algorithm
Clear()It is used to set a range of elements to zero, to null, or to false, depending on the type of element.
Empty()Simply returns an empty array.
Copy()This method copies elements of an array into another array by specifying the initial index and performs type casting as required.
CopyTo()Copies all the elements of the current one-dimensional array to the specified one-dimensional array.
Clone()This method creates a shallow copy of the Array.
CreateInstance()Using this method new instance of the Array class is initialized.
Initialize()This method initializes every element of the value-type Array by calling the default constructor of the value type.
IndexOf()This method searches for the specified object and returns the index of the first occurrence in a one-dimensional array.
Find()It is used to search for an element that matches the conditions defined by the specified predicate and returns the first occurrence within the entire Array.
Reverse()This method reverses the sequence of the elements in the entire one-dimensional Array.
ToString()It returns a string that represents the current object.
GetUpperBound()It is used to get the upper bound of the specified dimension in the Array.
GetLowerBound()It is used to get the lower bound of the specified dimension in the Array.
Sort()It is used to sort the elements in an entire one-dimensional Array by using the IComparable implementation of each element of the Array..
AsReadOnly()This method returns a read-only wrapper for the specified array.

C# program for Array Class

No let us see an example to demonstrate some of the methods of Array Class in C# programming.

Output:


MORE

String Pattern Programs in C

In this tutorial, we will write various C pattern programs for String. Before that, you may go through the following topics in C. for loop …
Read More

Java Program to Find pair of Integers in Array whose sum is given Number

In this tutorial, we will write a program to find a pair of elements from an array whose sum equals a given number in java …
Read More

Program to Print Diamond Alphabet Patterns in C

In this tutorial, we will learn to write a C program to print Diamond patterns using alphabets/characters. However, in this tutorial, we will create a …
Read More

Half Diamond Pattern in C using Alphabets

In this tutorial, we will learn and code the half diamond alphabet patterns in C programming language. However, in this tutorial, we will create a …
Read More

Half Pyramid of Alphabets in C

In this tutorial, we will learn and code alphabet patterns in C programming language specifically the Half pyramid of alphabets in C programming. However, in …
Read More

Inverted Half Pyramid Pattern of Alphabets in C

In this tutorial, we will write a C program to print half Pyramid using alphabets/characters. Before that, you may go through the following topic in …
Read More