473,616 Members | 2,970 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to initialize jagged array?

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[a,b] y[a,b] y[a,b]
x y[a,b]
x y[a,b] y[a,b]
x y[a,b] y[a,b] y[a,b] y[a,b]

I can initialize a jagged array of arrays like this:

string[][] str = new string[][]
{
new string[] {"loop for strings"},
new string[] {"loop for strings"},
};

which would give me this:

x y y y
x y
x y y
x y y y y

but how do I initialize the 2-Dim array on the "y" array?

I tried this:

string[][][,] str = new string[][][,]
{
new string[] {"loop for strings"},
new string[] {{"loop for strings"},
new string[,] {{"strD-1"}, {"strD-2"}}}
};

but no luck.

how do I initialize this type of array?

Thanks in advance.

Mar 11 '06 #1
2 6187
deko <de**@nospam.co m> wrote:
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[a,b] y[a,b] y[a,b]
x y[a,b]
x y[a,b] y[a,b]
x y[a,b] y[a,b] y[a,b] y[a,b]
<snip>
I tried this:

string[][][,] str = new string[][][,]


No - that's creating an array of arrays of rectangular arrays of
strings.

If you want something with a string and then an array of pairs, I
suggest you encapsulate that into your own type.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Mar 11 '06 #2
>> string[][][,] str = new string[][][,]

No - that's creating an array of arrays of rectangular arrays of
strings.
I think it might be something more like this (still pseudo code):

string[][][,] str = new string[3][][,]
str[0] = new string[2][,]
str[0][0] = new string[,] { { "str00a" }, { "str00b" } }
str[0][1] = new string[,] { { "str01a" }, { "str01b" } }
str[1] = new string[1][,]
str[1][0] = new string[,] { { "str10a" }, { "str10b" } }
str[2] = new string[1][,]
str[2][0] = new string[,] { { "str20a" }, { "str20b" } }

which is intented to be a jagged array of multidimensiona l arrays.

But I'm not sure what the correct syntax is, and how I would fill such a
thing in a loop.
If you want something with a string and then an array of pairs, I
suggest you encapsulate that into your own type.


Yes, that makes sense.
Mar 11 '06 #3

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

Similar topics

1
2719
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 loop in the constructor its ridiculously faster but even here its 4 times faster...is this correct?...
3
2193
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
5
12554
by: Benny Raymond | last post by:
Basically what the subject says... "in a bool 2d array, does Initialize set everything to false?"
1
10286
by: xllx.relient.xllx | last post by:
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;
4
2370
by: Alan Foxmore | last post by:
Hi everyone, I'm new to C# and I was hoping I could get some clarification on the syntax for jagged and multidimensional arrays. Here is my question: The following syntax is correct for declaring a multi-dimensional array:
2
3960
by: tiberiu.motoc | last post by:
Hi. I've asked this question on the MSDN forums, but I've had no replies. I'm really stuck, so I'm gonna try my luck here. I have a Java web service which contains a simple function; the function returns a double-dimensional array of integers. I ran the wsdl utility and I created a simple .NET web client which calls the function. I noticed that the result is returned as a jagged array, since multi-dimensional arrays cannot be...
5
10337
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
17
7236
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?
3
6098
by: pinkfloydfan | last post by:
Hi there I have a C# program that produces a lot of data that I currently store in a jagged array and I have a couple of questions that I was hoping someone might shed some light on for me please: 1) If the data is stored in MyData is there a way to do a query on the jagged array to get out say all the 100th entries of the 250,000 main arrays or am I better off with a for loop? 2) Do you have a better suggestion of how to store the...
0
8203
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8647
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8592
jinu1996
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8297
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8449
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7121
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6097
isladogs
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5550
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4141
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.