Example 1: array syntax c#
class TestArraysClass
{
static void Main()
{
int[] array1 = new int[5];
int[] array2 = new int[] { 1, 3, 5, 7, 9 };
int[] array3 = { 1, 2, 3, 4, 5, 6 };
int[,] multiDimensionalArray1 = new int[2, 3];
int[,] multiDimensionalArray2 = { { 1, 2, 3 }, { 4, 5, 6 } };
int[][] jaggedArray = new int[6][];
jaggedArray[0] = new int[4] { 1, 2, 3, 4 };
}
}
Example 2: c# array
int[] myArray = new int[];
myArray[0] = 2;
myArray[1] = 5;
myArray[2] = 9;
int[] myArray = {2, 5, 9};
int[] myArray = new int[]{2, 5, 9};
int[,] myRetArray = { {8, 2}, {9, 4} };
var myRetArray = new int[3, 5];
myRetArray[0,1] = 12;
var myJagArray = new int[3][];
myJagArray[0] = new int[2];
myJagArray[1] = new int[6];
myJagArray[2] = new int[4];
var myJagArray = new int[3][];
myJagArray[0] = new int[] {7, 8, 4, 6, 1};
myJagArray[1] = new int[] {2, 6, 6};
myJagArray[2] = new int[] {7, 12, 4, 9, 13, 10, 3};
int[][] myJagArray = new int[][]
{
new int[] {1, 4, 3},
new int[] {9, 2, 3},
new int[] {2, 5, 9}
};
var myArray = new int[3, 5, 8];
var my_list = new List<int>[] {
new List<int>() { 9, 2, 1, 2},
new List<int> { 6, 4, 1, 7},
new List<int> { 1, 8, 4, 3},
};
Console.WriteLine(my_list[0].ElementAt(0));
Example 3: make new array in c#
string[] stringArray = new string[6];