C# | Array Class - GeeksforGeeks

05 Aug, 2021
The Array class gives methods for creating, manipulating, searching, and sorting arrays. The Array class is not part of the System.Collections namespace, but it is still considered as a collection because it is based on the IList interface. The Array class is the base class for language implementations that support arrays.
Characteristics of Array Class: 
In Array, the elements are the value of the array and the length of the array is the total number of item present in the array.
The lower bound of an Array is the index of its first element and the default value of the lower bound is 0.
The default size of an Array is 2GB.
Array objects with the same array type share the same Type object.
Example: 
C#
// C# program to creating an array// of the string as coffee name, store// coffee name in the store,// and prints each value.using System;namespace geeksforgeeks { class GFG {     // Main Method    public static void Main()    {         // declares an 1D Array of string        string[] store;         // allocating memory for coffee names.        store = new string[] {"Americano, ", "Cafe au lait, ",                              "Espresso, ", "Cappuccino, ",                              "Long Black, ", "Macchiato" };         // Displaying Elements of the array        Console.WriteLine("Different types of coffee: ");        Console.WriteLine();        foreach(string coffeename in store)            Console.WriteLine(coffeename + " ");    }}}
Different types of coffee: 

Americano,  
Cafe au lait,  
Espresso,  
Cappuccino,  
Long Black,  
Macchiato
 
Example 1:
C#
// C# program to illustrate// Length property of Array classusing System;namespace geeksforgeeks { class GFG {     // Main Method    public static void Main()    {         // declares an 1D Array of string.        string[] topic;         // allocating memory for topic.        topic = new string[] {"Array, ", "String, ",                              "Stack, ", "Queue, ",                              "Exception, ", "Operators"};         // Displaying Elements of the array        Console.WriteLine("Topic of C#:");        Console.WriteLine();         // Here we calculate and print        // the length of the array, i.e. 6        Console.WriteLine("Length of the array: {0}",                                       topic.Length);        foreach(string ele in topic)            Console.WriteLine(ele + " ");    }}}
Topic of C#:

Length of the array: 6
Array,  
String,  
Stack,  
Queue,  
Exception,  
Operators
 
Example 2:
C#
// C# program to illustrate the// Rank property of Array classusing System;namespace geeksforgeeks { class GFG {     // Main Method    public static void Main()    {         // declares an 1D Array of string.        string[] topic;         // allocating memory for topic.        topic = new string[] {"Array, ", "String, ",                              "Stack, ", "Queue, ",                              "Exception, ", "Operators" };         // Displaying Elements of array        Console.WriteLine("Topic of C#:");        Console.WriteLine();         // Rank property provides the dimension rank        // here we use 1-D array so it return 1        // if we use 2-D array then it will return 2        Console.WriteLine("Rank of the array: {0}",                                         topic.Rank);        foreach(string ele in topic)            Console.WriteLine(ele + " ");    }}}
Topic of C#:

Rank of the array: 1
Array,  
String,  
Stack,  
Queue,  
Exception,  
Operators
 
Example 1:
C#
// C# program to illustrate the Reverse() Methodusing System;namespace geeksforgeeks { class GFG {     // Main Method    public static void Main()    {         // declares an 1D Array of string.        string[] topic;         // allocating memory for topic.        topic = new string[] {"Array, ", "String, ",                              "Stack, ", "Queue, ",                              "Exception, ", "Operators" };         // Displaying Elements of        // the array before reverse        Console.WriteLine("Topic of C# before reverse:");        Console.WriteLine();        foreach(string ele in topic)        {            Console.WriteLine(ele + " ");        }        Console.WriteLine();         // using Reverse() method to        // reverse the given array        Array.Reverse(topic);         // Displaying Elements of array after reverse        Console.WriteLine("Topic of C# after reverse:");        Console.WriteLine();        foreach(string val in topic)        {            Console.WriteLine(val + " ");        }    }}}
Topic of C# before reverse:

Array,  
String,  
Stack,  
Queue,  
Exception,  
Operators 

Topic of C# after reverse:

Operators 
Exception,  
Queue,  
Stack,  
String,  
Array,
 
Example 2:
C#
// C# program to illustrate the Sort() Methodusing System;namespace geeksforgeeks { class GFG {     // Main Method    public static void Main()    {         // declares an 1D Array of string.        string[] topic;         // allocating memory for topic.        topic = new string[] {"Array, ", "String, ",                              "Stack, ", "Queue, ",                              "Exception, ", "Operators" };         // Displaying Elements of the array before sort        Console.WriteLine("Topic of C# before reverse:");        Console.WriteLine();        foreach(string ele in topic)        {            Console.WriteLine(ele + " ");        }        Console.WriteLine();         // using Sort() method to        // sort the given array        Array.Sort(topic);         // Displaying Elements of        // array after sort        Console.WriteLine("Topic of C# after reverse:");        Console.WriteLine();        foreach(string val in topic)        {            Console.WriteLine(val + " ");        }    }}}
Topic of C# before reverse:

Array,  
String,  
Stack,  
Queue,  
Exception,  
Operators 

Topic of C# after reverse:

Array,  
Exception,  
Operators 
Queue,  
Stack,  
String,
 
Reference: 
https://docs.microsoft.com/en-us/dotnet/api/system.array?view=netframework-4.7.2
 
shubham_singh
anikakapoor
CSharp-Arrays
C#
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Difference between Abstract Class and Interface in C#
C# | How to check whether a List contains a specified element
C# | IsNullOrEmpty() Method
String.Split() Method in C# with Examples
Difference between Ref and Out keywords in C#
C# | Arrays of Strings
C# | Delegates
Top 50 C# Interview Questions & Answers
Extension Method in C#
C# | Abstract Classes