menu

Thursday, August 16, 2012

Jagged Array


What is jagged array?
    class Program
    {
        static void Main(string[] args)
        {
            int[][] arr = new int[3][]; // Jagged array
            int[] x1 = { 1,2,3,4,5,6,7,8,9,0};
            int[] x2 = { 1,3,5,7,9};
            int[] x3 = { 2,4,6,8};

            arr[0] = x1;
            arr[1] = x2;
            arr[2] = x3;

            for (int j = 0; j < 3; j++)
            {
                for (int i = 0; i < arr[j].Length; i++)
                {
                    Console.Write(arr[j][i].ToString()+ ", ");
                }
                Console.WriteLine();
            }
        }
    }

No comments:

Post a Comment