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
  1. Home
  2. General Programming
  3. C#
  4. creating dynamic array

creating dynamic array

Scheduled Pinned Locked Moved C#
csharpc++data-structuresquestion
9 Posts 5 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.
  • N Offline
    N Offline
    nuttynibbles
    wrote on last edited by
    #1

    i notice that in c# or c++, we normally indicate the size of an array. string[] strArray = new string[5]; strArray[0] = "Ronnie"; strArray[1] = "Jack"; strArray[2] = "Lori"; strArray[3] = "Max"; strArray[4] = "Tricky"; Another way is like this: string[] strArray = new string[] {"Ronnie", "Jack", "Lori", "Max", "Tricky"}; Both have fixed size. is there a way to create an array which can store unlimited amount of data? I know of ArrayList but it is not available in compact framework.

    D 1 Reply Last reply
    0
    • N nuttynibbles

      i notice that in c# or c++, we normally indicate the size of an array. string[] strArray = new string[5]; strArray[0] = "Ronnie"; strArray[1] = "Jack"; strArray[2] = "Lori"; strArray[3] = "Max"; strArray[4] = "Tricky"; Another way is like this: string[] strArray = new string[] {"Ronnie", "Jack", "Lori", "Max", "Tricky"}; Both have fixed size. is there a way to create an array which can store unlimited amount of data? I know of ArrayList but it is not available in compact framework.

      D Offline
      D Offline
      Dan Mos
      wrote on last edited by
      #2

      What about List? It has all the functionality of array/arrayList.

      N 1 Reply Last reply
      0
      • D Dan Mos

        What about List? It has all the functionality of array/arrayList.

        N Offline
        N Offline
        nuttynibbles
        wrote on last edited by
        #3

        okay my bad. arraylist is available in compact framework. however, im gonna try your suggestion instead. List looks like a better choice =)

        D 1 Reply Last reply
        0
        • N nuttynibbles

          okay my bad. arraylist is available in compact framework. however, im gonna try your suggestion instead. List looks like a better choice =)

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          Arrays in the .NET CLR are not resizable. Once they are created, that's it. In order to change their size, you'd have to create a new array of the required size, copy the data over, then destroy the original array.

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
               2006, 2007, 2008
          But no longer in 2009...

          N I 2 Replies Last reply
          0
          • D Dave Kreskowiak

            Arrays in the .NET CLR are not resizable. Once they are created, that's it. In order to change their size, you'd have to create a new array of the required size, copy the data over, then destroy the original array.

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                 2006, 2007, 2008
            But no longer in 2009...

            N Offline
            N Offline
            nuttynibbles
            wrote on last edited by
            #5

            tks Dave. =)

            1 Reply Last reply
            0
            • D Dave Kreskowiak

              Arrays in the .NET CLR are not resizable. Once they are created, that's it. In order to change their size, you'd have to create a new array of the required size, copy the data over, then destroy the original array.

              A guide to posting questions on CodeProject[^]
              Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                   2006, 2007, 2008
              But no longer in 2009...

              I Offline
              I Offline
              i gr8
              wrote on last edited by
              #6

              There is something called Redim which used to resize the array at later stage, or the best you can do is go for arraylist

              D 1 Reply Last reply
              0
              • I i gr8

                There is something called Redim which used to resize the array at later stage, or the best you can do is go for arraylist

                D Offline
                D Offline
                Dave Kreskowiak
                wrote on last edited by
                #7

                C# doesn't have a ReDim method like VB.NET does. And, in VB.NET ReDim does NOT resize an array. Behind the scenes it has to do the exact same thing you'd do manually. It creates a new array of the required size, copies the data to it, then destroys the original array.

                A guide to posting questions on CodeProject[^]
                Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                     2006, 2007, 2008
                But no longer in 2009...

                D 1 Reply Last reply
                0
                • D Dave Kreskowiak

                  C# doesn't have a ReDim method like VB.NET does. And, in VB.NET ReDim does NOT resize an array. Behind the scenes it has to do the exact same thing you'd do manually. It creates a new array of the required size, copies the data to it, then destroys the original array.

                  A guide to posting questions on CodeProject[^]
                  Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                       2006, 2007, 2008
                  But no longer in 2009...

                  D Offline
                  D Offline
                  Dave Doknjas
                  wrote on last edited by
                  #8

                  Actually, all .NET languages have access to the static "System.Array.Resize" method (since .NET Framework 2, I believe) - but as you said, there's no magic - it just does the same copying that VB's ReDim does.

                  David Anton Convert between VB, C#, C++, & Java www.tangiblesoftwaresolutions.com

                  D 1 Reply Last reply
                  0
                  • D Dave Doknjas

                    Actually, all .NET languages have access to the static "System.Array.Resize" method (since .NET Framework 2, I believe) - but as you said, there's no magic - it just does the same copying that VB's ReDim does.

                    David Anton Convert between VB, C#, C++, & Java www.tangiblesoftwaresolutions.com

                    D Offline
                    D Offline
                    Dave Kreskowiak
                    wrote on last edited by
                    #9

                    Yeah, I was saying that C# didn't have an equiv keyword to VB.NET's ReDim.

                    A guide to posting questions on CodeProject[^]
                    Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                         2006, 2007, 2008
                    But no longer in 2009...

                    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