Jagged Array in C#

Jagged array represents array of arrays where each array can have arbitrary number of elements. It’s the similar concept of double pointers in C.

Jagged array provides flexible services for manipulating and controlling data. In the case of C pointers will have to do the manual book keeping for better control over the bounds of data. We can have the same implementation by using dequeue/vector container classes in C++. But still we can’t say they’re representing array. Rather than they’re containers and provides common “container” interfaces.

You can check the number of facilities available for jagged arrays and arrays from MSDN. Also you will get some other good examples

How to use Jagged Arrays – Listing 1

// constructing jagged array

int[][] myJaggedArray = new int[5][];

for (int i = 0; i < myJaggedArray.Length; i++)

{

myJaggedArray[i] = new int[i + 1];

}

// iterating each arrays

for (int i = 0; i < myJaggedArray.Length; i++)

{

// iterating each elements in an array

for (int j = 0; j < myJaggedArray[i].Length; j++)

{

Console.Write( “{0} “, myJaggedArray[i][j]);

}

Console.WriteLine(” – {0} elements”, myJaggedArray[i].Length);

}

How to use Jagged Arrays – Listing 1

int[][,] jaggedArray4 = new int[3][,]

{

new int[,] { {1,3}, {5,7} },

new int[,] { {0,2}, {4,6}, {8,10} },

new int[,] { {11,22}, {99,88}, {0,9} }};

This entry was posted in Uncategorized. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

5 Comments

  1. Posted September 1, 2008 at 3:44 am | Permalink

    Hi!,

  2. Posted September 1, 2008 at 5:37 am | Permalink

    Good day!,

  3. Posted February 24, 2009 at 6:58 am | Permalink

    hi
    I feel you can explain it in a much better way so that even a fresher to programming can understand it…

  4. Posted December 30, 2009 at 11:47 am | Permalink

    hi,

    First of all. Thanks very much for your useful post.

    I just came across your blog and wanted to drop you a note telling you how impressed I was with the information you have posted here.

    Please let me introduce you some info related to this post and I hope that it is useful for .Net community.

    There is a good C# resource site, Have alook

    http://csharptalk.com

    simi

  5. Posted February 24, 2009 at 7:13 am | Permalink

    Dear Asha,

    Thanks for the input. I think I’ve given adquate links inline with the blog post. So that people can refer if they’re ignorant about it. There are different level of people who’s reading the blog posts, sometimes if I add all the things about double pointers and then that post can’t focus on it’s exact subject. Information overloaded. :)
    I still agree with you that I can improve my writings.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>