C# Array Class - Array Class and Functions in C#

C# Array Class

  • C# provides an Array class to deal with array related operations.
  • It provides methods for creating, searching, manipulating and sorting elements of an array.
  • In .NET programming environment this class works as the base class for all arrays.

C# Array class Signature

public abstract class Array : ICloneable, IList, ICollection,   
IEnumerable, IStructuralComparable, IStructuralEquatable  

Sample Code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Array_class
    class Program
        static void Main(string[] args)
            // Creating an array  
            int[] arr = new int[6] { 5, 8, 9, 25, 0, 7 };
            // Creating an empty array  
            int[] arr2 = new int[6];
            // Displaying length of array  
            Console.WriteLine("length of first array: " + arr.Length);
            // Sorting array  
            Console.WriteLine("First array elements: ");
            // Displaying sorted array  
            // Finding index of an array element  
            Console.WriteLine("\nIndex position of 25 is " + Array.IndexOf(arr, 25));
            // Coping first array to empty array  
            Array.Copy(arr, arr2, arr.Length);
            Console.WriteLine("Second array elements: ");
            // Displaying second array  
            Console.Write("\nFirst Array elements in reverse order: ");
        // User defined method for iterating array elements  
        static void PrintArray(int[] arr)
            foreach (Object elem in arr)
                Console.Write(elem + " ");


 C# array Class

Related Searches to C# Array Class - Array Class and Functions in C#