Multi-Dimensional Array in C#
C# underpins multidimensional arrays. The least complex type of the multidimensional array is the two-dimensional array.
Program
using System;
namespace Acces_Multi_Dimensional
{
class Program
{
static void Main(string[] args)
{
/*An array with 6 rows and 2 columns */
int[,] x = new int[6, 2] { { 0,10 }, { 1,45 }, { 2,60 }, { 3, 74 }, { 4,50 }, { 5,90 } };
int i, j;
/* Display each array elements */
for (i = 0; i < 6; i++)
{
for (j = 0; j < 2; j++)
{
Console.WriteLine("x[{0},{1}] = {2}", i, j, x[i, j]);
}
}
Console.ReadKey();
}
}
}
Output
x[0,0]=0
x[0,1]=10
x[1,0]=1
x[1,1]=45
x[2,0]=2
x[2,1]=60
x[3,0]=3
x[3,1]=74
x[4,0]=4
x[4,1]=50
x[5,0]=5
x[5,1]=90
C# underpins multidimensional arrays. The least complex type of the multidimensional array is the two-dimensional array.
Program
using System;
namespace Acces_Multi_Dimensional
{
class Program
{
static void Main(string[] args)
{
/*An array with 6 rows and 2 columns */
int[,] x = new int[6, 2] { { 0,10 }, { 1,45 }, { 2,60 }, { 3, 74 }, { 4,50 }, { 5,90 } };
int i, j;
/* Display each array elements */
for (i = 0; i < 6; i++)
{
for (j = 0; j < 2; j++)
{
Console.WriteLine("x[{0},{1}] = {2}", i, j, x[i, j]);
}
}
Console.ReadKey();
}
}
}
Output
x[0,0]=0
x[0,1]=10
x[1,0]=1
x[1,1]=45
x[2,0]=2
x[2,1]=60
x[3,0]=3
x[3,1]=74
x[4,0]=4
x[4,1]=50
x[5,0]=5
x[5,1]=90