C# Array

What is Array?
An array is a data structure which contains elements of same data type i.e. (Numbers, Words or Characters.). Arrays are commonly used in any programming language to store data in an organized manner.

What are the data type used in an array?
1. Integer (0-9)
2. String (a-z including numbers and nulled characters)

Integer Array
Let’s practice integer array in 2 small parts-

Part 1 – Initialize an int array with 5 elements

 //Part 1 - Initialize an int array with 5 elements  
 int[] array = {1, 2, 3, 4, 5 };


Part 2 – Make use of initialized array

 //Part 2 - Make use of initialized array  
 Console.WriteLine("Third element: {0}", array[2]); 
 OR
 Console.WriteLine("Third element: " + array[2]);  

* array[2] – here number 2 represent to third element in an array because array index starts with 0. Therefore, array[0] is 1.

String Array
Let’s practice string array in 2 small parts similar to int array-

Part 1 – Initialize an string array with 2 elements

 //Part 1 - Initialize an string array with 2 elements  
 string[] array = {"one", "two"};


Part 2 – Make use of initialized array

 //Part 2 - Make use of initialized array  
 Console.WriteLine("First element: {0}", array[0]); 
 OR
 Console.WriteLine("Second element: " + array[1]);