473,562 Members | 2,598 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Differences between Rectangular and Jagged Arrays

Hi, I have two questions:

1.)Is it true that an rectangular array is really just an single
dimensional array that lets itself be treated as a multi-dimensional

For example the following declaration:

int[,] rectangular = new int[5,10];

has it's memory layout in a sequential contiguous order, so, the above
is one big array consisting of 50 objects stored sequentially in
memory. Am I right?
2.) Jagged Arrays: These are truly, arrays of arrays unlike rectangular
arrays because; jagged arrays are not really stored in a sequential
order except for the first index; Example:

int[][] jagged = new int[5];

declares 5 sequential contiguous references in memory but the
sequential order stops at the following statement:

jagged[0] = new int[10];

the memory layout here is not sequential in order any more. correct?

So my conclusion is that this is the reason you have to type:

new int[] {1,2,3,4,5} ...

In a jagged initializer:

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

where in a rectangular array the expression:

new int [] {1,2,3,4,5} can be left out of the initializer:

int[,] rectangular = new int[,] {

for a jagged array but not a rectangular array because a rectangular
array, unlike a jagged one, has it's objects stored in a sequential
order whereas jaggs do not, hence the need for new int[] {1,2,3,4,5}.

I might be coming a little confusing here to some of you but I hope I
got through what I'm trying to say and things like this really matter
to me (trust me) so I need to get this through my head before I move


Jan 12 '06 #1
1 10267
I might be coming a little confusing here to some of you but I hope I
got through what I'm trying to say and things like this really matter
to me (trust me) so I need to get this through my head before I move

Yes your understanding is basically correct.

Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Jan 12 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Nikhil Patel | last post by:
Hi all, I am readin an MSDN tutorial on C# arrays. It says, you can have a three-dimensional rectangular array: int buttons = new int; What I don't understand is how can a three dimensional array be a rectangular array because a rectangle can have only two dimensions.Thanks in advance...-Nikhil
by: James dean | last post by:
I done a test and i really do not know the reason why a jagged array who has the same number of elements as a multidimensional array is faster here is my test. I assign a value and do a small calculation. Even if i initialise the jagged array inside the function it is still much faster. Are these results correct?. If i put the initialisation...
by: James dean | last post by:
I have created algorithms in C# unsafe code and have fixed the arrays in memory for optimum performance. I use multidimensional arrays rather than jagged arrays. The algorithms i use usually read a bitmap file sequentially so no random accessing different parts of the array. I know in microsoft site it says to use jagged arrays but in this...
by: Chris Wood | last post by:
I need to do a variable argument list in Managed C++, where each argument is a double array. I believe that this is impossible, because to do so I would need to make a jagged matrix of doubles, which is not supported. Does anyone know if this is impossible, or if there is some other way to do this? Using System.Array rather than double...
by: Ravi Singh (UCSD) | last post by:
Hello all I am trying to use jagged and multi-dimensional arrays in C++. In C# these work fine // for jagged arrays string jaggedArray = new string ; //for multidimensional arrays string multidimensionalArray = new string
by: deko | last post by:
I trying to create a jagged array of two arrays, with the second array being an array of two-dimensional arrays. A graphical representation might look like this: x y y y x y x y y x y y y y
by: TS | last post by:
is there some code somewhere that does this? i have a jagged array that is not jagged, it has an equal number of rows and columns in each array so it should convert but want to get the code to do it somewhere. thanks
by: =?Utf-8?B?TWljaGFlbA==?= | last post by:
Hello, i have a problem with jagged arrays and a webservice. I try to call a webservice with an array of a class that contains jagged arrays. Here is an example: class MyClass{ string myJaggedArray; string anotherString; }
by: =?Utf-8?B?U2hhcm9u?= | last post by:
Hi Gurus, I need to transfer a jagged array of byte by reference to unmanaged function, The unmanaged code should changed the values of the array, and when the unmanaged function returns I need to show the array data to the end user. Can I do that? How?
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.