cyberic
10
Q:

create an array in 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}; 
12
string[] stringArray = new string[6];
4
int[] Nameofarray = new int[how much is the max];

for example:
int[] X = new int[5];
10
string[] cars = {"Volvo", "BMW", "Ford", "Mazda"};
3
datatype variable[dimension]=new datatype[size]{array};
// for example:
string MyArray[]=new string[1]{"Hello","World"};
// or just:
string MyArray[]={"Hello","world"};
// for multidimensions:
// 2D array:
         	  // 2 arrays, 3 values //
int MyArray=[,]=new int[1,2]{
  {1,2,3},
  {1,2,3}
}
// 3D array:
              // 2 arrays, 3 arrays, 4 values //
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}
  }
}
0

New to Communities?

Join the community