473,385 Members | 1,465 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 6168
deko <de**@nospam.com> 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.com>
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 multidimensional 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
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...
3
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...
5
by: Benny Raymond | last post by:
Basically what the subject says... "in a bool 2d array, does Initialize set everything to false?"
1
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...
4
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...
2
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...
5
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...
17
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...
3
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.