473,396 Members | 1,834 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.

Multidimensional Array Hell - C# versus Java => C++ ???

Ole
Goodday everybody,

i want to create an array that represents data, that has to
be transferred to a pdf doc ( iTextSharp ).

The problem is, that i seem too loose my faith. Namely, ( i have
experiences in
c/c++, perl and i thouht in c#, too ), i do not succeed in creating a
multidimensional array. I have no experience in creating
multidimensional array in c#. The whole process looks so ugly to me,
that i really
think of throwing all that c# and java stuff against the wind in order
to
use good old c or c++ again.

Or, ... perhaps i'm too stupid.

So, if some programmer out there would like to draw another, deep
fallen programmer out of his depressions, what is wrong with the
following code: (???!!!)

using System;
namespace arraytest {
class Class1 {
[STAThread]
static void Main( string[] args ) {
// shouldn't the following statement create an 3-dimensional array
?
Array numbers = Array.CreateInstance( typeof ( Int32 ), 10, 4, 2
);
// and why isn't possible simply to do :
// numbers[][][] = new int[10][4][2] ?!
try {
for( int i = 0; i < 10; i++ ) {
for ( int y = 0; y < 4; i++ ) {
for( int j = 0; j < 2; j++ ) {
// please do not answer : "why do you not do
numbers.initialize ( )
// wordless!
numbers.SetValue( 100, i,y,j );
}
}
}
}catch ( Exception e ) {
System.Console.WriteLine( e.ToString ( ) );
System.Console.Read( );
}
}
}
}

Sure, i could create a row - class, that would be able to hold the
data and
put those row objects into an array. But i don't want't to
overobjectize
my clients' workstations!!

Please help me out here ...!

Thanks in advance, Ole.

PS ( to all the java programmers : how do you manage array
complications like this ? I saw something similar ugly in java . )

if ( noone.HelpsMe( ) ) {
throw new Languages ( "into the sea" );
}else {

put the System.Out && and goto bed;
}
bed:
Nov 15 '05 #1
10 2315
Ole wrote:
Please help me out here ...!


http://www.programmersheaven.com/2/Les_CSharp_8_p1

--
There are 10 kinds of people. Thos who understand binary and those who
don't.

http://code.acadx.com
(Pull the pin to reply)
Nov 15 '05 #2
Well, I dont know a whole lot about C# myself, but think you seem to be
using the wrong
syntax.

For a rectangualr array you would use:
int[,] matrix = new int[10,20] and access it as matrix[3,4] = 5;

For a jagged array you would use:
int[][] jarray = new int[3][]
jarray[0] = new int[10];
jarray[1] = new int[4];
jarray[2] = new int[1024];

To access this, you would use jarray[2][800] = 13;

for what it's worth, my 2 cents!
cheers
LK


"Ole" <ov*********@web.de> wrote in message
news:c6**************************@posting.google.c om...
Goodday everybody,

i want to create an array that represents data, that has to
be transferred to a pdf doc ( iTextSharp ).

The problem is, that i seem too loose my faith. Namely, ( i have
experiences in
c/c++, perl and i thouht in c#, too ), i do not succeed in creating a
multidimensional array. I have no experience in creating
multidimensional array in c#. The whole process looks so ugly to me,
that i really
think of throwing all that c# and java stuff against the wind in order
to
use good old c or c++ again.

Or, ... perhaps i'm too stupid.

So, if some programmer out there would like to draw another, deep
fallen programmer out of his depressions, what is wrong with the
following code: (???!!!)

using System;
namespace arraytest {
class Class1 {
[STAThread]
static void Main( string[] args ) {
// shouldn't the following statement create an 3-dimensional array
?
Array numbers = Array.CreateInstance( typeof ( Int32 ), 10, 4, 2
);
// and why isn't possible simply to do :
// numbers[][][] = new int[10][4][2] ?!
try {
for( int i = 0; i < 10; i++ ) {
for ( int y = 0; y < 4; i++ ) {
for( int j = 0; j < 2; j++ ) {
// please do not answer : "why do you not do
numbers.initialize ( )
// wordless!
numbers.SetValue( 100, i,y,j );
}
}
}
}catch ( Exception e ) {
System.Console.WriteLine( e.ToString ( ) );
System.Console.Read( );
}
}
}
}

Sure, i could create a row - class, that would be able to hold the
data and
put those row objects into an array. But i don't want't to
overobjectize
my clients' workstations!!

Please help me out here ...!

Thanks in advance, Ole.

PS ( to all the java programmers : how do you manage array
complications like this ? I saw something similar ugly in java . )

if ( noone.HelpsMe( ) ) {
throw new Languages ( "into the sea" );
}else {

put the System.Out && and goto bed;
}
bed:

Nov 15 '05 #3
Well, uh... your code for declaring the array isn't even close to the right
syntax for one thing.

string[,] names = new string[5,4];

works fine for me (straight out of the documentation), as does

string[,,] names = new string[5,4,8];
"Ole" <ov*********@web.de> wrote in message
news:c6**************************@posting.google.c om...
Goodday everybody,

// and why isn't possible simply to do :
// numbers[][][] = new int[10][4][2] ?!

Nov 15 '05 #4
Ole <ov*********@web.de> wrote:
i want to create an array that represents data, that has to
be transferred to a pdf doc ( iTextSharp ).
Do you really need it to be an array of arrays, or is a rectangular
array okay? If so, just use:

numbers[,,] = new int[10,4,2];

You could cast the result of Array.CreateInstance to int[,,] if you
wanted to.

I don't know why you can't initialise arrays of arrays in the way you
suggested (as you can in Java). Perhaps it's to encourage the use of
rectangular arrays for such cases.
PS ( to all the java programmers : how do you manage array
complications like this ? I saw something similar ugly in java . )


In Java you'd have been fine with:
int[][][] numbers = new int[10][4][2];

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

int[,,] myArray = new int[10,4,2];

--
Michael Culley
"Ole" <ov*********@web.de> wrote in message news:c6**************************@posting.google.c om...
Goodday everybody,

i want to create an array that represents data, that has to
be transferred to a pdf doc ( iTextSharp ).

The problem is, that i seem too loose my faith. Namely, ( i have
experiences in
c/c++, perl and i thouht in c#, too ), i do not succeed in creating a
multidimensional array. I have no experience in creating
multidimensional array in c#. The whole process looks so ugly to me,
that i really
think of throwing all that c# and java stuff against the wind in order
to
use good old c or c++ again.

Or, ... perhaps i'm too stupid.

So, if some programmer out there would like to draw another, deep
fallen programmer out of his depressions, what is wrong with the
following code: (???!!!)

using System;
namespace arraytest {
class Class1 {
[STAThread]
static void Main( string[] args ) {
// shouldn't the following statement create an 3-dimensional array
?
Array numbers = Array.CreateInstance( typeof ( Int32 ), 10, 4, 2
);
// and why isn't possible simply to do :
// numbers[][][] = new int[10][4][2] ?!
try {
for( int i = 0; i < 10; i++ ) {
for ( int y = 0; y < 4; i++ ) {
for( int j = 0; j < 2; j++ ) {
// please do not answer : "why do you not do
numbers.initialize ( )
// wordless!
numbers.SetValue( 100, i,y,j );
}
}
}
}catch ( Exception e ) {
System.Console.WriteLine( e.ToString ( ) );
System.Console.Read( );
}
}
}
}

Sure, i could create a row - class, that would be able to hold the
data and
put those row objects into an array. But i don't want't to
overobjectize
my clients' workstations!!

Please help me out here ...!

Thanks in advance, Ole.

PS ( to all the java programmers : how do you manage array
complications like this ? I saw something similar ugly in java . )

if ( noone.HelpsMe( ) ) {
throw new Languages ( "into the sea" );
}else {

put the System.Out && and goto bed;
}
bed:

Nov 15 '05 #6
Daniel Billingsley <db**********@NO.durcon.SPAAMM.com> wrote:
Well, uh... your code for declaring the array isn't even close to the right
syntax for one thing.


Yes it is - but only for declaring a jagged array, not a rectangular
array. The only problem is that in C# you can't instantiate a jagged
array in the same way that you can in Java.

--
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
Ole
Jon Skeet <sk***@pobox.com> wrote in message news:<MP************************@msnews.microsoft. com>...
Ole <ov*********@web.de> wrote:
i want to create an array that represents data, that has to
be transferred to a pdf doc ( iTextSharp ).


Do you really need it to be an array of arrays, or is a rectangular
array okay? If so, just use:

numbers[,,] = new int[10,4,2];

You could cast the result of Array.CreateInstance to int[,,] if you
wanted to.

I don't know why you can't initialise arrays of arrays in the way you
suggested (as you can in Java). Perhaps it's to encourage the use of
rectangular arrays for such cases.
PS ( to all the java programmers : how do you manage array
complications like this ? I saw something similar ugly in java . )


In Java you'd have been fine with:
int[][][] numbers = new int[10][4][2];


So you say that in java i can say

string [ ][ ] blabla = new string [ 10 ][ 5 ];

and access it like

blabla [ x ] [ y ] = "Glubberlutsch";

Is something similar possible in c# ?

Why do you have to access the other dimensions like as if they
were only other levels of the first dimension !? Or am i completely wrong ?

Greetings Ole.
Nov 15 '05 #8
Ole
Ok, i (tryto) think i have put my brain on and understood:

int [,,] = new int [10][][];
for rectangular arrays

and

Array bla = Array.CreateInstance ( typeof ( gerede ), new int []{1,2,3} );
for the others ( by the way, how are they called ? irrectangular ? )

"Michael Culley" <mc*****@NOSPAMoptushome.com.au> wrote in message news:<##**************@TK2MSFTNGP11.phx.gbl>...
Try

int[,,] myArray = new int[10,4,2];

--
Michael Culley
"Ole" <ov*********@web.de> wrote in message news:c6**************************@posting.google.c om...
Goodday everybody,

i want to create an array that represents data, that has to
be transferred to a pdf doc ( iTextSharp ).

The problem is, that i seem too loose my faith. Namely, ( i have
experiences in
c/c++, perl and i thouht in c#, too ), i do not succeed in creating a
multidimensional array. I have no experience in creating
multidimensional array in c#. The whole process looks so ugly to me,
that i really
think of throwing all that c# and java stuff against the wind in order
to
use good old c or c++ again.

Or, ... perhaps i'm too stupid.

So, if some programmer out there would like to draw another, deep
fallen programmer out of his depressions, what is wrong with the
following code: (???!!!)

using System;
namespace arraytest {
class Class1 {
[STAThread]
static void Main( string[] args ) {
// shouldn't the following statement create an 3-dimensional array
?
Array numbers = Array.CreateInstance( typeof ( Int32 ), 10, 4, 2
);
// and why isn't possible simply to do :
// numbers[][][] = new int[10][4][2] ?!
try {
for( int i = 0; i < 10; i++ ) {
for ( int y = 0; y < 4; i++ ) {
for( int j = 0; j < 2; j++ ) {
// please do not answer : "why do you not do
numbers.initialize ( )
// wordless!
numbers.SetValue( 100, i,y,j );
}
}
}
}catch ( Exception e ) {
System.Console.WriteLine( e.ToString ( ) );
System.Console.Read( );
}
}
}
}

Sure, i could create a row - class, that would be able to hold the
data and
put those row objects into an array. But i don't want't to
overobjectize
my clients' workstations!!

Please help me out here ...!

Thanks in advance, Ole.

PS ( to all the java programmers : how do you manage array
complications like this ? I saw something similar ugly in java . )

if ( noone.HelpsMe( ) ) {
throw new Languages ( "into the sea" );
}else {

put the System.Out && and goto bed;
}
bed:

Nov 15 '05 #9
Ole <ov*********@web.de> wrote:
In Java you'd have been fine with:
int[][][] numbers = new int[10][4][2];
So you say that in java i can say

string [ ][ ] blabla = new string [ 10 ][ 5 ];

and access it like

blabla [ x ] [ y ] = "Glubberlutsch";


Absolutely.
Is something similar possible in c# ?
Yes - as my message showed:

string [,] blabla = new string [10,5];

blabla [x,y] = "Glubberlutsch";

Note however that that's a rectangular array, as opposed to the Java
version which gives an array of arrays. You can create that as well in
C#, but it takes a little bit more work:

string[][] blabla = new string [10][];
for (int i=0; i < blabla.Length; i++)
blabla[i]=new string[5];

blabla [x][y] = "Glubberlutsch";

I suspect the reason that the C# syntax is longer is to encourage
people to use rectangular arrays in such situations.
Why do you have to access the other dimensions like as if they
were only other levels of the first dimension !? Or am i completely wrong ?


I suggest you look into arrays in a C# tutorial - it's not easy to
cover it in detail in news posts.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #10
Ole <ov*********@web.de> wrote:
Ok, i (tryto) think i have put my brain on and understood:

int [,,] = new int [10][][];
for rectangular arrays
No. You've got a rectangular array on the left hand side and a jagged
array on the right.
Array bla = Array.CreateInstance ( typeof ( gerede ), new int []{1,2,3} );
for the others ( by the way, how are they called ? irrectangular ? )


Jagged - or just an array of 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 #11

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

Similar topics

47
by: VK | last post by:
Or why I just did myArray = "Computers" but myArray.length is showing 0. What a hey? There is a new trend to treat arrays and hashes as they were some variations of the same thing. But they...
9
by: Charles Banas | last post by:
i've got an interesting peice of code i'm maintaining, and i'd like to get some opinions and comments on it, hopefully so i can gain some sort of insight as to why this works. at the top of the...
1
by: Mark Smith | last post by:
I'm trying to copy data from a 1D array to a 2D array. The obvious thing doesn't work: int twoDee = new int; int oneDee = new int { 1, 2 }; Array.Copy(oneDee, 2, twoDee, 2, 2); This causes a...
2
by: chris | last post by:
Hi there, I created a Multidimensional array of labels Label lblMultiArray = new Label { {Label3, LblThuTotal}, {Label4,LblFriTotal} }; Now I would like to compare the values in the array,...
10
by: | last post by:
I'm fairly new to ASP and must admit its proving a lot more unnecessarily complicated than the other languages I know. I feel this is because there aren't many good official resources out there to...
14
by: Michel Rouzic | last post by:
Hi, I've recently met issues with my program which can only be explained by heap corruption, so I've tried debugging my program with Valgrind, and here's what I get with the following...
9
by: JackpipE | last post by:
I need to create multidimensional array with arrays inside of it. database name | value1 | value2 john | red | 45 john | red | 56 john | yellow | 11 mike | blue | 23 mike | black | 41
1
by: The Hajj | last post by:
I've got an app I'm working on and a benefit to my users versus the old application is dynamic forms. I didn't want to do it at first but I figured it's something I'll have to do and the added...
9
by: Slain | last post by:
I need to convert a an array to a multidimensional one. Since I need to wrok with existing code, I need to modify a declaration which looks like this In the .h file int *x; in a initialize...
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: 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
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?
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
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...
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.