John Ware
0
Q:

how to make a c# array

// 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
// Array declaration by specifying size 
int arr1[10]; 
  
// With recent C/C++ versions, we can also 
// declare an array of user specified size 
int n = 10; 
int arr2[n]; 
// Array declaration by initializing elements 
int arr[] = { 10, 20, 30, 40 } 

// Compiler creates an array of size 4. 
// above is same as "int arr[4] = {10, 20, 30, 40}"
// Array declaration by specifying size and initializing 
// elements 
int arr[6] = { 10, 20, 30, 40 } 

// Compiler creates an array of size 6, initializes first 
// 4 elements as specified by user and rest two elements as 0. 
// above is same as "int arr[] = {10, 20, 30, 40, 0, 0}" 

14
int[] Nameofarray = new int[how much is the max];

for example:
int[] X = new int[5];
10
string[] cars = {"Volvo", "BMW", "Ford", "Mazda"};
3
type arrayName [ arraySize ];
9
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