473,545 Members | 2,085 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
array?

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[,] {
{1,2,3,4,5},
{6,7,8,9,10}};

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
ahead.

Thanks.

Jan 12 '06 #1
1 10262
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
ahead.

Yes your understanding is basically correct.
Mattias

--
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

2
6203
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
1
2712
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...
3
2552
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...
1
1265
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...
3
2186
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
2
6182
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
5
10327
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
0
2450
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; }
17
7220
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?
0
7656
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7419
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...
0
7756
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5971
agi2029
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...
0
4944
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...
0
3450
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3442
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1879
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
1
1014
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.