Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   C# (http://www.programmingforums.org/forum16.html)
-   -   Trouble understanding simple concepts (http://www.programmingforums.org/showthread.php?t=10319)

52Degrees Jun 12th, 2006 7:52 PM

Trouble understanding simple concepts
 
I'm reading my C# book just about every day during lunchtime since that is the best time for me to understand new stuff.

I'm in the middle of learning about arrays and come up to these "jagged" arrays. I can understand the idea of arrays having non constant dimensions, but there's something I just don't get.

:

int [,,] ia3d=new int [3,2,4] {{{8, 3, 4, 2}, {7, 4, 1, 2}},
                              {{2, 7, 3, 6}, {5, 1, 9, 0}},
                              {{0, 4, 9, 7}, {3, 9, 8, 5}}};


Can someone (or several of you) explain to me what is happening in this line in such a manner that I might understand it?

Thanks.

DaWei Jun 12th, 2006 8:16 PM

Why do you call them jagged arrays? It's quite regular. Consider a spreadsheet with 10 columns and 4 rows. That isn't even, but it's regular. Now consider a second sheet behind that one, with the same 10 columns and 4 rows. You now have a multidimensional array that is 2 x 4 x 10. Add rows. Add columns. Add row:n col m: on page 1 to row:n col:m on page 2. No biggie.

52Degrees Jun 12th, 2006 8:34 PM

The book I'm reading called them jagged. That wasn't the problem I'm having.

[3,2,4] I'm seeing this a 3 high, 2 wide and 4 deep, right?




Oh, SHIT!!!

Nevermind. I'm an idiot.

DaWei Jun 12th, 2006 8:40 PM

It does vary from language to language (Fortran is not the same as C). I don't know dink about C#, but it's probably the same as C/C++: [most significant]....[least significant]. Least significant signifying that the index is the most rapidly varying. A true array can be represented by a linear stretch of memory, regardless of dimensions.

52Degrees Jun 12th, 2006 8:47 PM

Yeah. I was having a momentary lapse of reason. For some reason I was looking at that line and just not understanding what i was seeing. It was really frustrating because I knew that I knew it, but couldn't figure it out.

Jason Isom Jun 12th, 2006 9:12 PM

Quote:

Originally Posted by 52Degrees
Yeah. I was having a momentary lapse of reason. For some reason I was looking at that line and just not understanding what i was seeing. It was really frustrating because I knew that I knew it, but couldn't figure it out.

You may want to look at your book again because there is a difference between a jagged array and a regular array. What you posted is a multi-dimensional regular array, as Dawei already pointed out. If your book is calling those jagged arrays, you may want to invest in a better book.

52Degrees Jun 12th, 2006 9:34 PM

It's not, I was saying I understood that concept. What I didn't understand was what I was looking at. Because my brain decided to attempt to divide by zero or something.

Just waiting for splinter to chime in ;)


All times are GMT -5. The time now is 8:03 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC