Array class and function in C#

In this chapter you will learn:

  • Various types of array’s properties
  • Various types of array’s function
  • How to use array’s properties and function in C# programming?

The Array class is the base class of all the arrays in C sharp programming. Array class is defined within the system namespace. Array class provides number of predefined functions and properties to work with. Its function makes array much easier and simpler to work.

Most common properties of Array class

Properties Explanation Example
Length Returns the length of array. Returns integer value. int i = arr1.Length;
Rank Returns total number of items in all the dimension. Returns integer value. int i = arr1.Rank;
IsFixedSize Check whether array is fixed size or not. Returns Boolean value bool i = arr.IsFixedSize;
IsReadOnly Check whether array is ReadOnly or not. Returns Boolean value bool k = arr1.IsReadOnly;

Most common functions of Array class

Function Explanation Example
Sort Sort an array Array.Sort(arr);
Clear Clear an array by removing all the items Array.Clear(arr, 0, 3);
GetLength Returns the number of elements arr.GetLength(0);
GetValue Returns the value of specified items arr.GetValue(2);
IndexOf Returns the index position of value Array.IndexOf(arr,45);
Copy Copy array elements to another elements Array.Copy(arr1,arr1,3);

Programming Examples of array class


Length:   5
Rank:      1
Fixed Size:       True
Read Only:       FalseElements of array is:5      14      25      33      43

Get Length:      5
Get Value:       25
Get Index:       3

Elements of array is:

5      14      25      33      43

Elements of array is:

0      0        0       0        0



In this chapter you learned about different types of array’s properties and function in C#. In next chapter you will get some programming examples of array.

Leave a Reply

Your email address will not be published. Required fields are marked *