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
[SerializableAttribute]
[ComVisibleAttribute(true)]
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
{
staticvoid 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 Array.Sort(arr);
Console.WriteLine("First array elements: ");
// Displaying sorted array
PrintArray(arr);
// 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
PrintArray(arr2);
Array.Reverse(arr);
Console.Write("\nFirst Array elements in reverse order: ");
PrintArray(arr);
}
// User defined method for iterating array elements staticvoid PrintArray(int[] arr)
{
foreach (Object elem in arr)
{
Console.Write(elem + " ");
Console.ReadLine();
}
}
}
}
Related Searches to C# Array Class - Array Class and Functions in C#
c# array classarray classsystem.array class using c#working with arrays in c#c# arraysc# arrays and classesarray class and function in c#c# array methods listarray of class objects in c#system.array c#c# class array initializationc# array of class typesarray in c#array functions in c# with examples