Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Handling array argument!

Handling array argument!

Scheduled Pinned Locked Moved C#
questioncsharpdata-structures
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    C NewBe
    wrote on last edited by
    #1

    I am converting vb6 code to C# and I have a question regarding array argument. In vb6 the array argument below sometimes take the form of 1Dimension or MultiD where it is Redim depending on how it comes. C# does not allow this.....my question is, how do I handle it? public double[] ConvertMatrixToBase0(double[] MyMat) { long i, j; double[] ConvMat; if(MultiDimensional(MyMat) == false) //1-dimensional array { ConvMat = new double[MyMat.GetLength(1) - 1]; //ReDim ConvMat(UBound(MyMat, 1) - 1) for(i=1; i<=MyMat.GetLength(1); i++) //For i = 1 To UBound(MyMat, 1) ConvMat[i - 1] = MyMat[i]; } else //multi-dimensional array { ConvMat = new double[MyMat.GetLength(1)-1, MyMat.GetLength(2)-1]; //ReDim ConvMat(UBound(MyMat, 1) - 1, UBound(MyMat, 2) - 1) for(i=1; i<=MyMat.GetLength(1); i++) //For i = 1 To UBound(MyMat, 1) { for(j=1; j<=MyMat.GetLength(2); j++) //For j = 1 To UBound(MyMat, 2) ConvMat[i-1,j-1] = MyMat[i,j]; } } return ConvMat; }

    L 1 Reply Last reply
    0
    • C C NewBe

      I am converting vb6 code to C# and I have a question regarding array argument. In vb6 the array argument below sometimes take the form of 1Dimension or MultiD where it is Redim depending on how it comes. C# does not allow this.....my question is, how do I handle it? public double[] ConvertMatrixToBase0(double[] MyMat) { long i, j; double[] ConvMat; if(MultiDimensional(MyMat) == false) //1-dimensional array { ConvMat = new double[MyMat.GetLength(1) - 1]; //ReDim ConvMat(UBound(MyMat, 1) - 1) for(i=1; i<=MyMat.GetLength(1); i++) //For i = 1 To UBound(MyMat, 1) ConvMat[i - 1] = MyMat[i]; } else //multi-dimensional array { ConvMat = new double[MyMat.GetLength(1)-1, MyMat.GetLength(2)-1]; //ReDim ConvMat(UBound(MyMat, 1) - 1, UBound(MyMat, 2) - 1) for(i=1; i<=MyMat.GetLength(1); i++) //For i = 1 To UBound(MyMat, 1) { for(j=1; j<=MyMat.GetLength(2); j++) //For j = 1 To UBound(MyMat, 2) ConvMat[i-1,j-1] = MyMat[i,j]; } } return ConvMat; }

      L Offline
      L Offline
      led mike
      wrote on last edited by
      #2

      double[,] matrix = new double[10, 10];

      led mike

      C 1 Reply Last reply
      0
      • L led mike

        double[,] matrix = new double[10, 10];

        led mike

        C Offline
        C Offline
        C NewBe
        wrote on last edited by
        #3

        led mike, I don't think I did a good job describing the problem. It should have been how to handle a dynamic array argument in c#. From readings that I have done, I do not think it's possible. I think I have to use Arraylist.

        N 1 Reply Last reply
        0
        • C C NewBe

          led mike, I don't think I did a good job describing the problem. It should have been how to handle a dynamic array argument in c#. From readings that I have done, I do not think it's possible. I think I have to use Arraylist.

          N Offline
          N Offline
          Not Active
          wrote on last edited by
          #4

          You would be better off using a generic collection rather than an arraylist


          only two letters away from being an asset

          C 1 Reply Last reply
          0
          • N Not Active

            You would be better off using a generic collection rather than an arraylist


            only two letters away from being an asset

            C Offline
            C Offline
            C NewBe
            wrote on last edited by
            #5

            I am going to look into collection but can you educate a bit about the differences between the two? Thanks

            N 1 Reply Last reply
            0
            • C C NewBe

              I am going to look into collection but can you educate a bit about the differences between the two? Thanks

              N Offline
              N Offline
              Not Active
              wrote on last edited by
              #6

              Given your example using an ArrayList you would incur a boxing/unboxing penalty everytime to stored or accessed the values since ArrayList uses object. Using a generic collection, say List you would not have this issue, with the additional benefit of being typesafe.


              only two letters away from being an asset

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups