Jagged Array in .NET

namespace JaggedArray
{
    class Program
    {
        static void Main(string[] args)
        {
            int[][] a;
            a = new int[2][];
            a[0] = new int [3];
            a[1] =new int [5];

            // populate data

            int counter=0;
            foreach (int[] d in a)
            {
                for (int i = 0; i < d.Length; i++)
                {
                    d[i] = counter;
                    counter++;
                }
            }


            //1D fron 2D array

            foreach (int[] d in a)
            {
                foreach (int e in d)
                {
                    Console.Write(" {0} ", e);
                }
                Console.WriteLine();
            }
            Console.Read();

        }
    }
}

SHARE THE KNOWLEDGE


  

Advertisements

About Dinesh

I am engineering student........ I am selected in Microsoft Student Partner as MSP............

Posted on August 4, 2011, in .NET, Knowledge. Bookmark the permalink. Leave a comment.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: