473,396 Members | 1,938 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,396 software developers and data experts.

Two dimensional array initialization

Hi,

I can make a simple initialization work like this:

Object[,] ONE_ROW = {{"Vodafone", "5550160100197016"}};

But, now I want to create another array that consists of multiple copies of ONE_ROW like this (will not compile):

Object[,] TWO_ROWS = {ONE_ROW, ONE_ROW}; // Works in Java ;-)

This yields "Incorrectly structured array initializer"!!

This, however, is a correct implementation using hard-coded data:

Object[,] TWO_ROWS = {{"Vodafone", "5550160100197016"}, {"Vodafone", "5550160100197016"}};

Any ideas?

Regards,
Dadi.
Nov 15 '05 #1
9 8557
Dadi <da**@hugur.is> wrote:
I can make a simple initialization work like this:

Object[,] ONE_ROW = {{"Vodafone", "5550160100197016"}};

But, now I want to create another array that consists of multiple copies
of ONE_ROW like this (will not compile):


It sounds like you want jagged arrays then, rather than rectangular
arrays. If you do:

Object[][,] TWO_ROWS = {ONE_ROW, ONE_ROW}; I believe it'll work.

(Haven't tried it though...)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #2
Actually Jon I think he wants

Object[][] TWO_ROWS =

a jagged array of ONE_ROW arrays. Your code would be a jagged array of 2D
rectangular arrays which I don't think was the intent, wouldn't it?

I've been wrong about arrays before so maybe I am again.

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Dadi <da**@hugur.is> wrote:
I can make a simple initialization work like this:

Object[,] ONE_ROW = {{"Vodafone", "5550160100197016"}};

But, now I want to create another array that consists of multiple copies
of ONE_ROW like this (will not compile):


It sounds like you want jagged arrays then, rather than rectangular
arrays. If you do:

Object[][,] TWO_ROWS = {ONE_ROW, ONE_ROW}; I believe it'll work.

(Haven't tried it though...)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 15 '05 #3
Daniel Billingsley <db**********@NO.durcon.SPAAMM.com> wrote:
Actually Jon I think he wants

Object[][] TWO_ROWS =

a jagged array of ONE_ROW arrays. Your code would be a jagged array of 2D
rectangular arrays which I don't think was the intent, wouldn't it?


I don't know - the intent wasn't very clear! However, my code would
give a single array of 2D rectangular arrays.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #4
That's what I said, isn't it? :)

I meant your overall array [][,] would be jagged, as opposed to simply 3D
[,,].

Yes, no, maybe so? (Trying to see if I'm starting to grasp this terminology
as well as I think I am.)

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
... Your code would be a jagged array of 2D
rectangular arrays which I don't think was the intent, wouldn't it?


I don't know - the intent wasn't very clear! However, my code would
give a single array of 2D rectangular arrays.

Nov 15 '05 #5
Daniel Billingsley <db**********@NO.durcon.SPAAMM.com> wrote:
That's what I said, isn't it? :)
Not quite - it's definitely *not* a jagged array *of* 2D rectangular
arrays, in the same way that int[] isn't a jagged array of ints, it's
just an array of ints, if you see what I mean.
I meant your overall array [][,] would be jagged, as opposed to simply 3D
[,,].


I'm not sure whether I'd say the overall array is jagged or not - it's
certainly not rectangular, but it's not jagged in the normal sense
either.

Fortunately this is unlikely to actually be an issue very often :)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #6
Hmm... I thought jagged simply meant an array of arrays... what did you mean
by the "normal sense" of jagged usage?

an array of ints is 1 dimensional, and not relevant to this discussion in my
mind.

an array of arrays, or an array of arrays of arrays, or an array of 2D
arrays, are all "jagged" I would think by definition, no?

[,] defines 2D array, definitely not jagged
[][] defines array of arrays, definitely jagged

[][,] defines an array of 2D arrays, jagged, right?
[][][] defines an array of arrays of arrays, jagged, right?
[,,] defines a 3D array, not jagged, right?

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Daniel Billingsley <db**********@NO.durcon.SPAAMM.com> wrote:
That's what I said, isn't it? :)


Not quite - it's definitely *not* a jagged array *of* 2D rectangular
arrays, in the same way that int[] isn't a jagged array of ints, it's
just an array of ints, if you see what I mean.
I meant your overall array [][,] would be jagged, as opposed to simply 3D [,,].


I'm not sure whether I'd say the overall array is jagged or not - it's
certainly not rectangular, but it's not jagged in the normal sense
either.

Fortunately this is unlikely to actually be an issue very often :)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 15 '05 #7
Daniel Billingsley <db**********@NO.durcon.SPAAMM.com> wrote:
Hmm... I thought jagged simply meant an array of arrays... what did you mean
by the "normal sense" of jagged usage?
I'd say that a jagged array of "X"s is an array of arrays of "X"s.
an array of ints is 1 dimensional, and not relevant to this discussion in my
mind.
Ah, but it is in mine. Here's a jagged array of ints:

int[][] x;

That means a jagged array *of* arrays is similarly:

Something[][][] x;

That's a jagged array of (Something[]).

Just

Something[][] x;

is a jagged array of (Something) instead.

In this case we have:

Something[][,];

which is a one-dimensional array of (Something[,]), rather than a
jagged array of Something[,]. It may or may not (see below) count as a
jagged array of Something. Semi-jagged perhaps?
an array of arrays, or an array of arrays of arrays, or an array of 2D
arrays, are all "jagged" I would think by definition, no?


Not sure. Possibly, possibly not. My main point was that it wasn't a
jagged array of 2D arrays, but now we're getting into deeper water :)

I keep flip-flopping on whether or not I'd consider it jagged in
general. I think I probably would, on balance, contrary to my previous
post.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #8
I'm sure where you landed when you flip-flopped, so I don't know if we're
still disagreeing. :)

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Daniel Billingsley <db**********@NO.durcon.SPAAMM.com> wrote:
Hmm... I thought jagged simply meant an array of arrays... what did you mean by the "normal sense" of jagged usage?
I'd say that a jagged array of "X"s is an array of arrays of "X"s.


Yes I agree. MS defines a jagged array as "an array whose elements are
arrays." But there is no specification of what that second "of arrays"
looks like - 1D, 2D, 3D doesn't change the definition.

Something[][,];

which is a one-dimensional array of (Something[,]), rather than a
jagged array of Something[,]. It may or may not (see below) count as a
jagged array of Something. Semi-jagged perhaps?
Is Something[,] not an array? Then that makes Something[][,] an
array of arrays, and therefore jagged by definition, just as MS explains a
bit further down on that same doc page:

"It is possible to mix jagged and multidimensional arrays. The following is
a declaration and initialization of a single-dimensional jagged array that
contains two-dimensional array elements of different sizes:

int [] [,] myJaggedArray = new int [] [3,] { new int [,] " blah blah blah

Not sure. Possibly, possibly not. My main point was that it wasn't a
jagged array of 2D arrays, but now we're getting into deeper water :)


Sure looks to me like MS just said [][,] is a jagged array of 2D arrays.

I'm sorry, I'm not trying to be a smart alec proving you wrong per se.. it's
just that I find myself completely confused and wrong enough that when I
think I've got something nailed for once I've got to cling to it
desperately. LOL.
Nov 15 '05 #9
I meant I'm *NOT* sure, of course. I've been typing like a retard all day.
Need coffee.

"Daniel Billingsley" <db**********@NO.durcon.SPAAMM.com> wrote in message
news:us**************@TK2MSFTNGP11.phx.gbl...
I'm sure where you landed when you flip-flopped, so I don't know if we're
still disagreeing. :)

Nov 15 '05 #10

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

Similar topics

2
by: ip4ram | last post by:
I used to work with C and have a set of libraries which allocate multi-dimensional arrays(2 and 3) with single malloc call. data_type **myarray =...
4
by: Grumble | last post by:
Hello, Is it not legal in C90 to initialize a multi-dimensional array with a one-dimensional initializer as done below? int a = { 1, 2, 3, 4, 5, 6, 7, 8 }; My compiler complains:...
4
by: Richard Hayden | last post by:
Hi, Why does gcc (3.3.2) give me a 'initialization from incompatible pointer type' warning when compiling: int main(int argc, char** argv) { int testa; int** testp = testa; }
7
by: ashu | last post by:
look at code #include<stdio.h> int *mult(void); int main(void) { int *ptr,i; ptr=mult; for(i=0;i<6;i++) { printf("%d",*(ptr++));
4
by: TG | last post by:
Hi there ! I'm just starting to use Numeric here, and I'm wondering : how can I efficiently initialize every values of a N-dimensional array, given I don't know the number of dimensions ? I'm...
8
by: kd | last post by:
Newbie question here. It's been a while since I've done C programming, and I hit a wall last night. Let's say I have a three dimensional array, like so: int p = {{{0,0,0}, {1,1,1},...
5
by: David T. Ashley | last post by:
Hi, Aside from the obvious recursive syntax for initialization, $x = array( ... array( ...)), what is the best way to deal with multi-dimensional arrays in PHP? It seems there is no...
4
by: Gernot Frisch | last post by:
Hi, I need a class, that has a 4 dimensional array (can be 3 dimensional, too) with such an operator: T operator()(int x1, int x2=0, int x3=0, int x4=0); that can be used as:
152
by: vippstar | last post by:
The subject might be misleading. Regardless, is this code valid: #include <stdio.h> void f(double *p, size_t size) { while(size--) printf("%f\n", *p++); } int main(void) { double array = { {...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
0
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...
0
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,...

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.