473,666 Members | 2,143 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Multidimensiona l 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
multidimensiona l array. I have no experience in creating
multidimensiona l 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.CreateIns tance( 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.initial ize ( )
// wordless!
numbers.SetValu e( 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 2343
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*********@we b.de> wrote in message
news:c6******** *************** ***@posting.goo gle.com...
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
multidimensiona l array. I have no experience in creating
multidimensiona l 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.CreateIns tance( 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.initial ize ( )
// wordless!
numbers.SetValu e( 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*********@we b.de> wrote in message
news:c6******** *************** ***@posting.goo gle.com...
Goodday everybody,

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

Nov 15 '05 #4
Ole <ov*********@we b.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.CreateIns tance 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.co m>
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*********@we b.de> wrote in message news:c6******** *************** ***@posting.goo gle.com...
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
multidimensiona l array. I have no experience in creating
multidimensiona l 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.CreateIns tance( 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.initial ize ( )
// wordless!
numbers.SetValu e( 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**********@N O.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.co m>
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.co m> wrote in message news:<MP******* *************** **@msnews.micro soft.com>...
Ole <ov*********@we b.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.CreateIns tance 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.CreateIns tance ( typeof ( gerede ), new int []{1,2,3} );
for the others ( by the way, how are they called ? irrectangular ? )

"Michael Culley" <mc*****@NOSPAM optushome.com.a u> wrote in message news:<##******* *******@TK2MSFT NGP11.phx.gbl>. ..
Try

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

--
Michael Culley
"Ole" <ov*********@we b.de> wrote in message news:c6******** *************** ***@posting.goo gle.com...
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
multidimensiona l array. I have no experience in creating
multidimensiona l 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.CreateIns tance( 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.initial ize ( )
// wordless!
numbers.SetValu e( 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*********@we b.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.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #10

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

Similar topics

47
5061
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 are not at all. If you are doing *array", then you have to use only integer values for array index, as it was since ALGOL.
9
6665
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 function (which was translated from Fortran code), among other heinous and numerous declarations, is this bit: static float bbuff; static int bkey; static int buse;
1
8254
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 RankException. But the MSDN documentation says: When copying between multidimensional arrays, the array
2
12825
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, comparing the text in Label3 and LblThuTotal and the text in Label4 and LblFriTotal.
10
12199
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 help do the most basic things. One of the "basic" things I haven't been able to find out how to do is how to delete an item from a multidimensional array object and resize it afterwards. It seems so easy to conceive of the code to delete...
14
2881
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 multidimensional array allocation code : typedef struct { int32_t speed;
9
1901
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
2195
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 benefit is experience. Enough of the filler... I'm generating the forms with javascript, based on information I know. I use that information to tag the fields with that information. I can't go into too much detail as I don't have the code with me...
9
4494
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 function: x = new int;
0
8781
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
8551
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
7386
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
6198
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
5664
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
4369
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2771
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1776
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.