Creating an Array: Difference between revisions

Content added Content deleted
No edit summary
Line 190:
myArray5.Add(1);
myArray5.Add(2);
 
==[[C#]]==
 
Example of array of 10 int types:
 
int[] numbers = new int[10];
 
Example of array of 3 string types:
 
string[] words = { "these", "are", "arrays" };
 
You can also declare the size of the array and initialize the values at the same time:
 
int[] more_numbers = new int[3]{ 21, 14 ,63 };
 
 
For Multi-Deminsional arrays you delcare them the same except for a comma in the type declaration.
 
The following creates a 3x2 int matrix
int[,] number_matrix = new int[3][2];
 
As with the previous examples you can also initialize the values of the array, the only difference being each row in the matrix must be enclosed in its own braces.
 
string[,] string_matrix = { {"I","swam"}, {"in","the"}, {"freezing","water"} };
 
or
 
string[,] funny_matrix = new string[2][2]{ {"clowns", "are"} , {"not", "funny"} };