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

LengthReturns the length of array. Returns integer i = arr1.Length;
RankReturns total number of items in all the dimension. Returns integer i = arr1.Rank;
IsFixedSizeCheck whether array is fixed size or not. Returns Boolean valuebool i = arr.IsFixedSize;
IsReadOnlyCheck whether array is ReadOnly or not. Returns Boolean valuebool k = arr1.IsReadOnly;

Most common functions of Array class

SortSort an arrayArray.Sort(arr);
ClearClear an array by removing all the itemsArray.Clear(arr, 0, 3);
GetLengthReturns the number of elementsarr.GetLength(0);
GetValueReturns the value of specified itemsarr.GetValue(2);
IndexOfReturns the index position of valueArray.IndexOf(arr,45);
CopyCopy array elements to another elementsArray.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.


More Examples


Leave a Reply

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