You are on page 1of 1

using System;

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WorkingWithArrays
{
class JaggedArray
{
public static void Start()
{
int[][] IntJagged = CreateJaggedArray(3);
Console.WriteLine("Length={0}", IntJagged.Length);
Console.WriteLine("GetLength(0)={0}", IntJagged.GetLength(0));
//Console.WriteLine("GetLength(1)={0}", IntJagged.GetLength(1));
PopulateJaggedArray(IntJagged);
PrintJaggedArray(IntJagged);
QuickCreateJagged();

}
public static void QuickCreateJagged()
{
int[][] IntJagged = new int[3][] {
new int[2] { 1, 2 },
new int[3] { 1, 2, 3 },
new int[5] { 1, 2 , 3, 4, 5}
};

PrintJaggedArray(IntJagged);
}
public static int[][] CreateJaggedArray(int Length)
{
int[][] Jagged = new int[Length][];
return Jagged;
}
public static void PopulateJaggedArray(int[][] Jagged)
{
for(int i=0; i<Jagged.Length; i++)
{
int[] Array = new int[i + 1];
Program.PopulateArray(Array);
Jagged[i] = Array;
}
}
public static void PrintJaggedArray(int[][] Jagged)
{
foreach(int[] e in Jagged)
{
foreach(int i in e)
{
Console.Write("{0} ", i);
}
Console.WriteLine();
}
}
}
}

You might also like