c# array
int[] array = new int[]{1, 2, 3, 4, 5};
foreach (string i in array)
{
Console.WriteLine(i);
}
//or
for(int i=0; i<array.Length; i++){
Console.WriteLine(array[i]);
}
c# array
int[] array = new int[]{1, 2, 3, 4, 5};
foreach (string i in array)
{
Console.WriteLine(i);
}
//or
for(int i=0; i<array.Length; i++){
Console.WriteLine(array[i]);
}
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 };
}
}
make new array in c#
string[] stringArray = new string[6];
how to make a c# array
// Syntax:
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}
}
}
Defining a new array with elements in c#
int [] marks = new int[] { 99, 98, 92, 97, 95};
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us