473,883 Members | 2,361 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Two dimensional array initialization

Hi,

I can make a simple initialization work like this:

Object[,] ONE_ROW = {{"Vodafone", "55501601001970 16"}};

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 "Incorrectl y structured array initializer"!!

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

Object[,] TWO_ROWS = {{"Vodafone", "55501601001970 16"}, {"Vodafone", "55501601001970 16"}};

Any ideas?

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

Object[,] ONE_ROW = {{"Vodafone", "55501601001970 16"}};

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.co m>
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.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Dadi <da**@hugur.i s> wrote:
I can make a simple initialization work like this:

Object[,] ONE_ROW = {{"Vodafone", "55501601001970 16"}};

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.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 15 '05 #3
Daniel Billingsley <db**********@N O.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.co m>
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.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
... 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**********@N O.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.co m>
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.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Daniel Billingsley <db**********@N O.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.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 15 '05 #7
Daniel Billingsley <db**********@N O.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.co m>
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.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Daniel Billingsley <db**********@N O.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 multidimensiona l 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**********@N O.durcon.SPAAMM .com> wrote in message
news:us******** ******@TK2MSFTN GP11.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
7675
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 = (data_type**)malloc(widht*height*sizeof(data_type)+ height* sizeof(data_type*)); //allocate individual addresses for row pointers. Now that I am moving to C++,am looking for something by which I can
4
26552
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: example.c:1: warning: missing braces around initializer example.c:1: warning: (near initialization for `a')
4
2256
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
5834
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
2319
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 looking for something like a map function, or a way to conveniently iterate through the whole N-array, but I didn't find anything ... yet. If anyone has a clue, I'm listening.
8
2684
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}, {0,1,0}},
5
1637
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 syntax like $x???
4
559
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
9984
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 = { { 3.14 }, { 42.6 } }; f((double *)array, sizeof array / sizeof **array); return 0;
0
9953
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
10768
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
10868
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
9588
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
7980
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
5808
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6009
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4231
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3242
bsmnconsultancy
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.