How to define an array class in C#?


The Array class is the base class for all the arrays in C#. It is defined in the System namespace and has the following properties −

Sr.NoProperty & Description
1IsFixedSize
Gets a value indicating whether the Array has a fixed size.
2IsReadOnly
Gets a value indicating whether the Array is read-only.
3Length
Gets a 32-bit integer that represents the total number of elements in all the dimensions of the Array.
4LongLength
Gets a 64-bit integer that represents the total number of elements in all the dimensions of the Array.
5Rank
Gets the rank (number of dimensions) of the Array.

To define an array class, you can try to run the following code, wherein we are sorting an array −

Example

 Live Demo

using System;

namespace Demo {
   class MyArray {
      static void Main(string[] args) {
         int[] list = { 45, 19, 9, 28, 87};
         int[] temp = list;
         Console.Write("Original Array: ");

         foreach (int i in list) {
            Console.Write(i + " ");
         }
         Console.WriteLine();

         Array.Sort(list);
         Console.Write("Sorted Array: ");

         foreach (int i in list) {
            Console.Write(i + " ");
         }
         Console.WriteLine();
         Console.ReadKey();
      }
   }
}

Output

Original Array: 45 19 9 28 87
Sorted Array: 9 19 28 45 87

Updated on: 20-Jun-2020

126 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements