Jagged arrays in C#
C# underpins multidimensional arrays, which are varieties of arrays.
Program
using System;
namespace Jagged_arrays
{
class Program
{
static void Main(string[] args)
{
/*Declaration of two elements*/
int[][] x= new int[2][];
/* Initialization of the elements */
x[0] = new int[5] { 1, 2, 3, 4, 5 };
x[1] = new int[6] { 10, 45, 60, 74, 50,90 };
/* To Display array elements*/
for (int i = 0; i < x.Length; i++)
{
System.Console.Write("Row [" + i + "] Elements ");
for (int y = 0; y < x[i].Length; y++)
Console.Write(x[i][y] + " ");
Console.WriteLine();
}
Console.ReadKey();
}
}
}
Output
Row[0] Elements 1 2 3 4 5
Row[1] Elements 10 45 60 74 50 90
C# underpins multidimensional arrays, which are varieties of arrays.
Program
using System;
namespace Jagged_arrays
{
class Program
{
static void Main(string[] args)
{
/*Declaration of two elements*/
int[][] x= new int[2][];
/* Initialization of the elements */
x[0] = new int[5] { 1, 2, 3, 4, 5 };
x[1] = new int[6] { 10, 45, 60, 74, 50,90 };
/* To Display array elements*/
for (int i = 0; i < x.Length; i++)
{
System.Console.Write("Row [" + i + "] Elements ");
for (int y = 0; y < x[i].Length; y++)
Console.Write(x[i][y] + " ");
Console.WriteLine();
}
Console.ReadKey();
}
}
}
Output
Row[0] Elements 1 2 3 4 5
Row[1] Elements 10 45 60 74 50 90