Example 1: c# create array
int[] arr = {1, 2, 3};
int[] arr;
arr = new int[] {1, 2, 3};
Example 2: how to make a c# array
datatype_variable[dimension] = new datatype[size]{array};
string MyArray[] = new string[1]{"Hello","World"};
string MyArray[]={"Hello","world"};
int MyArray=[,]=new int[1,2]{
{1,2,3},
{1,2,3}
}
int MyArray=[,,]=new int[1,2,3]{
{
{1,2,3,4},
{1,2,3,4},
{1,2,3,4}
},
{
{1,2,3,4},
{1,2,3,4},
{1,2,3,4}
}
}
Example 3: c# array of objects
T[] InitializeArray<T>(int length) where T : new() {
T[] array = new T[length];
for (int i = 0; i < length; ++i) {
array[i] = new T();
}
return array;
}
MyObjects[] my_objects = InitializeArray<MyObjects>(10);