c# how to use array code example
Example 1: hwo to make an array in C#
int[] Nameofarray = new int[how much is the max];
for example:
int[] X = new int[5];
Example 2: array syntax c#
class TestArraysClass
{
static void Main()
{
// Declare a single-dimensional array of 5 integers.
int[] array1 = new int[5];
// Declare and set array element values.
int[] array2 = new int[] { 1, 3, 5, 7, 9 };
// Alternative syntax.
int[] array3 = { 1, 2, 3, 4, 5, 6 };
// 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 };
}
}
Example 3: c# how to crete array
//you can apply arrays to any variable
//string array
string[] names = {"Guy", "Ryan", "Jim"};
//int array
int[] ages = {14, 16, 17, 19};
//double array
double[] timeRecord = {2.3, 5.6, 3.3};
Example 4: c# array set values
private string[] Exemple = { "1", "2", "3" };