Jagged array with 3 rows of different lengths

CSharp · Console

/Program.cs

using System;

public class Program
{
	public static void Main()
	{
		int[][] intArray = new int[3][];
		intArray[0] = new int[2]{1, 2};
		intArray[1] = new int[3]{3, 4, 5};
		intArray[2] = new int[4]{6, 7, 8, 9};
		
		// OR
		int[][] intArray1 = {new int[]{1, 2}, new int[]{3, 4, 5}, new int[]{6, 7, 8, 9}};
		// OR
		int[][] intArray2 = new int[][] { new int[] { 1, 2 }, new int[] { 3, 4, 5 }, new int[] { 6, 7, 8, 9 } };
		// OR 
		int[][] intArray3 = { new int[] { 1, 2 }, new int[] { 3, 4, 5 }, new int[] { 6, 7, 8, 9 } };
		// OR
		var intArray4 =  new[] { new int[] { 1, 2 }, new int[] { 3, 4, 5 }, new int[] { 6, 7, 8, 9 } };
		
		Console.WriteLine(intArray[0][1]);
		Console.WriteLine(intArray[1][2]);
		Console.WriteLine(intArray[2][3]);
		
		Console.WriteLine("----");
		
		Console.WriteLine(intArray1[0][1]);
		Console.WriteLine(intArray1[1][2]);
		Console.WriteLine(intArray1[2][3]);
	}
}
;