array c#

C#
// Define and Initialize
int[] arr = {1, 2, 3};

// Buuuut:
// Initial defining
int[] arr;

// This works
arr = new int[] {1, 2, 3};   

// This will cause an error
// arr = {1, 2, 3}; int[] array = new int[]{1, 2, 3, 4, 5};
foreach (string i in array) 
{
  Console.WriteLine(i);
}

//or

for(int i=0; i<array.Length; i++){
	  Console.WriteLine(array[i]);
}int[] Nameofarray = new int[how much is the max];

for example:
int[] X = new int[5];string[] cars = {"Volvo", "BMW", "Ford", "Mazda"};
Console.WriteLine(cars[0]);
// Outputs Volvo
var intArray = new[] { 1, 2, 3, 4, 5 };
var list = new List<int>(intArray);string[] cars = {"Volvo", "BMW", "Ford", "Mazda"};

Source

Also in C#: