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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ole

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

    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:
  • Frank Oquendo

    #2
    Re: Multidimensiona l Array Hell - C# versus Java =&gt; C++ ???

    Ole wrote:
    [color=blue]
    > Please help me out here ...![/color]



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


    (Pull the pin to reply)


    Comment

    • Laxmikant Rashinkar

      #3
      Re: Multidimensiona l Array Hell - C# versus Java =&gt; C++ ???

      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" <oviaudmurat@we b.de> wrote in message
      news:c640408c.0 310010759.2d69b 151@posting.goo gle.com...[color=blue]
      > 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:[/color]


      Comment

      • Daniel Billingsley

        #4
        Re: Multidimensiona l Array Hell - C# versus Java =&gt; C++ ???

        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" <oviaudmurat@we b.de> wrote in message
        news:c640408c.0 310010759.2d69b 151@posting.goo gle.com...[color=blue]
        > Goodday everybody,
        >
        > // and why isn't possible simply to do :
        > // numbers[][][] = new int[10][4][2] ?![/color]


        Comment

        • Jon Skeet

          #5
          Re: Multidimensiona l Array Hell - C# versus Java =&gt; C++ ???

          Ole <oviaudmurat@we b.de> wrote:[color=blue]
          > i want to create an array that represents data, that has to
          > be transferred to a pdf doc ( iTextSharp ).[/color]

          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.
          [color=blue]
          > PS ( to all the java programmers : how do you manage array
          > complications like this ? I saw something similar ugly in java . )[/color]

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

          --
          Jon Skeet - <skeet@pobox.co m>
          Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

          If replying to the group, please do not mail me too

          Comment

          • Michael Culley

            #6
            Re: Multidimensiona l Array Hell - C# versus Java =&gt; C++ ???

            Try

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

            --
            Michael Culley


            "Ole" <oviaudmurat@we b.de> wrote in message news:c640408c.0 310010759.2d69b 151@posting.goo gle.com...[color=blue]
            > 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:[/color]


            Comment

            • Jon Skeet

              #7
              Re: Multidimensiona l Array Hell - C# versus Java =&gt; C++ ???

              Daniel Billingsley <dbillingsley@N O.durcon.SPAAMM .com> wrote:[color=blue]
              > Well, uh... your code for declaring the array isn't even close to the right
              > syntax for one thing.[/color]

              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 - <skeet@pobox.co m>
              Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

              If replying to the group, please do not mail me too

              Comment

              • Ole

                #8
                Re: Multidimensiona l Array Hell - C# versus Java =&gt; C++ ???

                Jon Skeet <skeet@pobox.co m> wrote in message news:<MPG.19e53 2d246f6a2ed9897 ad@msnews.micro soft.com>...[color=blue]
                > Ole <oviaudmurat@we b.de> wrote:[color=green]
                > > i want to create an array that represents data, that has to
                > > be transferred to a pdf doc ( iTextSharp ).[/color]
                >
                > 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.
                >[color=green]
                > > PS ( to all the java programmers : how do you manage array
                > > complications like this ? I saw something similar ugly in java . )[/color]
                >
                > In Java you'd have been fine with:
                > int[][][] numbers = new int[10][4][2];[/color]

                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.

                Comment

                • Ole

                  #9
                  Re: Multidimensiona l Array Hell - C# versus Java =&gt; C++ ???

                  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" <mculley@NOSPAM optushome.com.a u> wrote in message news:<##44X5GiD HA.3104@TK2MSFT NGP11.phx.gbl>. ..[color=blue]
                  > Try
                  >
                  > int[,,] myArray = new int[10,4,2];
                  >
                  > --
                  > Michael Culley
                  >
                  >
                  > "Ole" <oviaudmurat@we b.de> wrote in message news:c640408c.0 310010759.2d69b 151@posting.goo gle.com...[color=green]
                  > > 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:[/color][/color]

                  Comment

                  • Jon Skeet

                    #10
                    Re: Multidimensiona l Array Hell - C# versus Java =&gt; C++ ???

                    Ole <oviaudmurat@we b.de> wrote:[color=blue][color=green]
                    > > In Java you'd have been fine with:
                    > > int[][][] numbers = new int[10][4][2];[/color]
                    >
                    > So you say that in java i can say
                    >
                    > string [ ][ ] blabla = new string [ 10 ][ 5 ];
                    >
                    > and access it like
                    >
                    > blabla [ x ] [ y ] = "Glubberlutsch" ;[/color]

                    Absolutely.
                    [color=blue]
                    > Is something similar possible in c# ?[/color]

                    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.
                    [color=blue]
                    > 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 ?[/color]

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

                    --
                    Jon Skeet - <skeet@pobox.co m>
                    Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

                    If replying to the group, please do not mail me too

                    Comment

                    • Jon Skeet

                      #11
                      Re: Multidimensiona l Array Hell - C# versus Java =&gt; C++ ???

                      Ole <oviaudmurat@we b.de> wrote:[color=blue]
                      > Ok, i (tryto) think i have put my brain on and understood:
                      >
                      > int [,,] = new int [10][][];
                      > for rectangular arrays[/color]

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

                      Jagged - or just an array of arrays.

                      --
                      Jon Skeet - <skeet@pobox.co m>
                      Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

                      If replying to the group, please do not mail me too

                      Comment

                      Working...