Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

arrays in c#

// There are actually many ways to create an array in C#

// The worst method
int[] array1 = new int[3];
array1[0] = 1;
array1[1] = 2;
array1[2] = 3;

// Declare a single-dimensional array of 5 integers
int[] array1 = new int[5];

// Declare and set array element values
int[] array2 = new int[5] { 1, 2, 3, 4, 5 };

// Alternative syntax
int[] array3 = { 1, 2, 3, 4, 5 };

// Declare a two dimensional array
int[,] multiDimensionalArray1 = new int[2, 3];

// Declare and set array element values
int[,] multiDimensionalArray2 = { { 1, 2, 3 }, { 4, 5, 6 } };

// Declare a jagged array
int[][] jaggedArray = new int[6][];

// Set the values of the first array in the jagged array structure
jaggedArray[0] = new int[4] { 1, 2, 3, 4 };
Source by www.codecademy.com #
 
PREVIOUS NEXT
Tagged: #arrays
ADD COMMENT
Topic
Name
8+9 =