Geekpedia Tutorials Home

Building a C# Chat Client and Server

Building a C# Chat Client and ServerA step by step tutorial teaching you how to create your own chat client and chat server easily in C#, for local networks or the Internet.

in C# Programming Tutorials

Getting Hard Drive Information

Getting Hard Drive InformationA C# tutorial showing you how to make use of WMI to extract information on disk drives, such as model, capacity, sectors and serial number.

in C# Programming Tutorials

UPS Shipping Calculator

UPS Shipping CalculatorThis tutorial will teach you how to calculate the shipping cost based on the weight, height, length and depth of the box, the distance and the UPS service type.

in PHP Programming Tutorials

Create Your Own Rich Text Editor

Create Your Own Rich Text EditorCreating a Rich Text Editor using JavaScript is easier to do than you might think, thanks to the support of modern browsers; this tutorial will walk you through it.

in JavaScript Programming Tutorials
Search
Tutorials
Programming Tutorials
IT Jobs
From CareerBuilder

Jagged arrays

This tutorial explains what a jagged array by giving an example that shows you how set and retrieve values.

On Sunday, July 25th 2004 at 11:34 PM
By Andrew Pociu (View Profile)
*****   (Rated 4.6 with 17 votes)
Contextual Ads
More C# Resources
Advertisement
They say a jagged array is an array of arrays.

It's not so hard to comprehend this. In the following example we declare jaggedArray named jArray that can hold 3 other arrays:




int[][] jArray = new int[3][];



Next you can set the size (number of elements) of each of the 3 arrays:





jArray[0] = new int[2];

jArray[1] = new int[5];

jArray[2] = new int[7];



The first array (0) has 2 elements, the second (1) has 5 elements and the third (2) has 7 elements.



How do we assign and retrieve values from the elements of each array?

As you can see in the followin graphic, first we specify the number of the array, second we specify the number of the element:








In the following example we assign values to all the elements in all 3 arrays:





// Fill the array no. 0

jArray[0][0] = 10;

jArray[0][1] = 11;



// Fill the array no. 1


jArray[1][0] = 20;

jArray[1][1] = 21;

jArray[1][2] = 22;

jArray[1][3] = 23;

jArray[1][4] = 24;



// Fill the array no. 2


jArray[2][0] = 30;

jArray[2][1] = 31;

jArray[2][2] = 32;

jArray[2][3] = 33;

jArray[2][4] = 34;

jArray[2][5] = 35;

jArray[2][6] = 36;



Using two loops we can retrieve the values of the elements from all the arrays inside the jagged array:





// Loop through the 3 arrays

for
(int i = 0; i < jArray.GetLength(0); i++)

{

   // Loop through the elements of the current array


   for(int x = 0; x < jArray[i].GetLength(0); x++)

   {

      Console.WriteLine(jArray[i][x].ToString());

   }

   Console.WriteLine("------");

}



If you compile the code, here's the result in the console window:





10

11

------

20

21

22

23

24

------

30

31

32

33

34

35

36

------

Press any key to continue
Digg Digg It!     Del.icio.us Del.icio.us     Reddit Reddit     StumbleUpon StumbleIt     Newsvine Newsvine     Furl Furl     BlinkList BlinkList

Rate Rate this tutorial
Comment Current Comments
by disantha on Thursday, September 2nd 2004 at 04:18 AM

what's the GetLength do? i can't understand it properly

by LeVirus Watts on Saturday, August 5th 2006 at 01:23 PM

disantha,
The .GetLength(x) ask the program how long the array in question is. (note: the x is which dimintion we are asking for.)

by onome ofu on Friday, March 2nd 2007 at 03:28 AM

This is a beautiful job.

by on Sunday, November 11th 2007 at 05:10 AM

thanks

by Haider on Monday, December 28th 2009 at 09:53 AM

very very easy tutorial im highly impressed from the way Andrew brother illustrated and demonstrated jagged array and now i completely understand, i read 3 ebooks but didnt understand how to use jagged arrays untill now because of their technical jorgans and shitty examples with mathematical complexities :)

by Larson on Friday, January 28th 2011 at 04:42 PM

Thanks man - I concur with Haider :-). Still being used through 2011.

by dwi on Monday, April 18th 2011 at 08:51 AM

thx man, this is what i want to search

by balance transfer credit card on Monday, December 12th 2011 at 05:34 AM

Use System.Windows.Forms.Cursor.Position to get the cursor position in screen coordinates.I admire the important information you offer within your content. I'll bookmark your web site and have my kids examine up the following typically.

by Margarita on Saturday, January 14th 2012 at 01:36 AM

Once you have recreated the problem and captured these steps, you can save them to a file and send it to your support person, who can then open it up and view

by beats by dre rouge on Thursday, March 1st 2012 at 08:50 PM

This article is very interesting, sharing is a wise choice, would like to see more about yourarticle

by michael kors bags on Sunday, March 18th 2012 at 08:55 PM

Thank you for sharing, I will often come to patronize your site

by camping lanterns on Thursday, April 12th 2012 at 05:50 AM

Much appreciated for the information and share!

by BYOD on Tuesday, June 5th 2012 at 01:34 AM

Isn't each of the square brackets used in any of the ways you have introduced arrays so far?I think this means that the first square bracket can be used as its own one-dimensional array or as a multi-dimensional array.

by Marco on Thursday, June 21st 2012 at 04:24 PM

Google themes are a welcome addition to the gmail experience. I tried out several themes, from nature to cartoon themes but I chose to return to the clear classic blue theme. They say classic never dies, I agree.

by Louis Vuitton Purses on Friday, August 17th 2012 at 10:31 PM

http://www.louisvuittonpursebags.org/ Louis Vuitton Purses
http://www.louisvuittonsonlineshop.org/ Louis Vuitton Outlet
http://www.greatlouisvuittonsbags.com/ louis vuitton outlet
http://www.cheap-suprashoe.net/ supra shoes
http://www.officiallouisvuittonzones.net/ louis vuitton outlet
http://www.hermesoutletsus.net/ hermes bags

by spideroak dropbox on Tuesday, October 2nd 2012 at 02:26 AM

this means that the first square bracket can be used as its own one-dimensional array or as a multi-dimensional array.

by invisible fence batteries r21 on Wednesday, October 24th 2012 at 07:05 AM

used as its own one-dimensional array or as a multi-dimensional array.

by car accident lawyer Dallas on Thursday, November 1st 2012 at 10:16 AM

Once you have recreated the problem and captured these steps, you can save them to a file and send it to your support person, who can then open it up and view

by new roof contractors on Wednesday, November 7th 2012 at 10:35 AM

This was a really quality post. In theory I'd like to write like this too - taking time and real effort to make a good article... but what can I say... I procrastinate a lot and never seem to get something done. orlando roofing contractor

by new roof contractors on Wednesday, November 7th 2012 at 10:37 AM

This was a really quality post. In theory I'd like to write like this too - taking time and real effort to make a good article... but what can I say... I procrastinate a lot and never seem to get something done. orlando roofing contractor

by new roof contractors on Wednesday, November 7th 2012 at 10:37 AM

This was a really quality post. In theory I'd like to write like this too - taking time and real effort to make a good article... but what can I say... I procrastinate a lot and never seem to get something done. orlando roofing contractor

by orlando roofing contractor on Wednesday, November 7th 2012 at 10:41 AM

This was a really quality post. In theory I'd like to write like this too - taking time and real effort to make a good article... but what can I say... I procrastinate a lot and never seem to get something done.

by tubal reversals on Friday, December 14th 2012 at 07:15 AM

Dream as if you will stay permanently. Live as if you will die nowadays.
http://www.tubal-reversal-surgery.net/services

by Houston dentist on Monday, December 17th 2012 at 01:56 PM

Houston dentistVery nice article, I enjoyed reading your post, very nice share,
I want to twit this to my followers. Thanks!.

by Houston dentist on Monday, December 17th 2012 at 01:56 PM

Houston dentistVery nice article, I enjoyed reading your post, very nice share,
I want to twit this to my followers. Thanks!.

by Houston dentist on Monday, December 17th 2012 at 01:56 PM

Houston dentistVery nice article, I enjoyed reading your post, very nice share,
I want to twit this to my followers. Thanks!.

by Houston dentist on Monday, December 17th 2012 at 01:56 PM

Houston dentistVery nice article, I enjoyed reading your post, very nice share,
I want to twit this to my followers. Thanks!.

by Houston dentist on Monday, December 17th 2012 at 01:56 PM

Houston dentistVery nice article, I enjoyed reading your post, very nice share,
I want to twit this to my followers. Thanks!.

by Houston dentist on Monday, December 17th 2012 at 01:56 PM

Houston dentistVery nice article, I enjoyed reading your post, very nice share,
I want to twit this to my followers. Thanks!.

by Houston dentist on Monday, December 17th 2012 at 01:57 PM

Houston dentistVery nice article, I enjoyed reading your post, very nice share,
I want to twit this to my followers. Thanks!.

by Houston dentist on Monday, December 17th 2012 at 01:57 PM

Houston dentistVery nice article, I enjoyed reading your post, very nice share,
I want to twit this to my followers. Thanks!.

by Houston dentist on Monday, December 17th 2012 at 01:57 PM

Houston dentistVery nice article, I enjoyed reading your post, very nice share,
I want to twit this to my followers. Thanks!.

by Houston dentist on Monday, December 17th 2012 at 01:57 PM

Houston dentistVery nice article, I enjoyed reading your post, very nice share,
I want to twit this to my followers. Thanks!.

by Houston dentist on Monday, December 17th 2012 at 01:57 PM

Houston dentistVery nice article, I enjoyed reading your post, very nice share,
I want to twit this to my followers. Thanks!.

by Houston dentist on Monday, December 17th 2012 at 01:57 PM

Houston dentistVery nice article, I enjoyed reading your post, very nice share,
I want to twit this to my followers. Thanks!.

by Houston dentist on Monday, December 17th 2012 at 01:57 PM

Houston dentistVery nice article, I enjoyed reading your post, very nice share,
I want to twit this to my followers. Thanks!.

by Houston dentist on Monday, December 17th 2012 at 01:57 PM

Houston dentistVery nice article, I enjoyed reading your post, very nice share,
I want to twit this to my followers. Thanks!.

by Houston dentist on Monday, December 17th 2012 at 01:57 PM

Houston dentistVery nice article, I enjoyed reading your post, very nice share,
I want to twit this to my followers. Thanks!.

by Houston dentist on Monday, December 17th 2012 at 01:57 PM

Houston dentistVery nice article, I enjoyed reading your post, very nice share,
I want to twit this to my followers. Thanks!.

by Houston dentist on Monday, December 17th 2012 at 01:57 PM

Houston dentistVery nice article, I enjoyed reading your post, very nice share,
I want to twit this to my followers. Thanks!.

by Houston dentist on Monday, December 17th 2012 at 01:57 PM

Houston dentistVery nice article, I enjoyed reading your post, very nice share,
I want to twit this to my followers. Thanks!.

by Houston dentist on Monday, December 17th 2012 at 01:57 PM

Houston dentistVery nice article, I enjoyed reading your post, very nice share,
I want to twit this to my followers. Thanks!.

by Houston dentist on Monday, December 17th 2012 at 01:57 PM

Houston dentistVery nice article, I enjoyed reading your post, very nice share,
I want to twit this to my followers. Thanks!.

by Houston dentist on Monday, December 17th 2012 at 01:57 PM

Houston dentistVery nice article, I enjoyed reading your post, very nice share,
I want to twit this to my followers. Thanks!.

by Houston dentist on Monday, December 17th 2012 at 01:57 PM

Very nice article, I enjoyed reading your post, very nice share,
I want to twit this to my followers. Thanks!.

by Houston dentist on Monday, December 17th 2012 at 01:57 PM

Very nice article, I enjoyed reading your post, very nice share,
I want to twit this to my followers. Thanks!.

by Houston dentist on Monday, December 17th 2012 at 01:57 PM

Very nice article, I enjoyed reading your post, very nice share,
I want to twit this to my followers. Thanks!.

by tubal reversal on Thursday, December 27th 2012 at 04:49 AM

I have joined her sessions and experienced her capability to express the details and encounter of the bottles of wine in an friendly fun way
http://www.tubal-reversal-surgery.net/services

by tubal reversal surgery on Friday, December 28th 2012 at 04:38 AM

The greatest advantages in discussing fact is that you never need to keep in mind what you said earlier…!
http://tubal-ligation-reversal-surgery.blogspot.com/2012/12/chances-of-conceiving-after-tubal.html

by Houston dentist on Sunday, December 30th 2012 at 10:53 AM

This is a smart blog. I norm it.You be inflicted with so greatly information in this vicinity this issue, and so greatly passion.Houston dentist

by Tubal reversal cost on Wednesday, January 16th 2013 at 05:44 AM

I would recommend my buddies to study this. I am quite sure they will comprehend plenty of new things here than anybody else!
http://www.tubal-reversal-surgery.net/tubal-ligation-reversal-financing-and-insurance-coverage.html

by web hosting on Wednesday, January 23rd 2013 at 11:26 PM

WOW.. an excellent details about Buy medication or Medication... excellent material with excellent achievements... keep operating on excellent details ... thanks for it.
http://www.softhof.com/

by khan on Thursday, February 7th 2013 at 02:27 AM

This was a really quality post. In theory I'd like to write like this too - taking time and real effort to make a good article...but what can I say... I procrastinate a lot and never seem to get something done.home page

by khan on Thursday, February 7th 2013 at 02:27 AM

This was a really quality post. In theory I'd like to write like this too - taking time and real effort to make a good article...but what can I say... I procrastinate a lot and never seem to get something done.home page


Comment Comment on this tutorial
Name: Email:
Message:
Comment Related Tutorials
There are no related tutorials.

Comment Related Source Code
There is no related source code.

Jobs C# Job Search
My skills include:
Enter a City:

Select a State:


Advanced Search >>
Ads

From the creators of Geekpedia, a revolutionary new coupon website!

BargainEZ has coupons codes, printable coupons, bargains and it is the leading source of Passbook coupons for iPhone and iPod touch devices.

Coupons
Discover Geekpedia
Other Resources