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. Visual Basic
  4. Convert array to arraylist problem

Convert array to arraylist problem

Scheduled Pinned Locked Moved Visual Basic
databasedata-structureshelptutorialquestion
5 Posts 2 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.
  • E Offline
    E Offline
    ESTAN
    wrote on last edited by
    #1

    hello guys I have the following code: Dim lineArray As String() = ProcessBuffer.ToString.Split(ControlChars.Cr) Dim lineArrayList As ArrayList = ArrayList.Adapter(lineArray) I use the Adapter method to convert my array to an arraylist, what is far more easy to work in my program. Now when i want to remove a index I get this exception. Unhandled Exception: System.NotSupportedException: Collection was of a fixed size. at System.Array.System.Collections.IList.RemoveAt(Int32 index) at System.Collections.IListWrapper.RemoveAt(Int32 index) Anyone an idea how to avoid this problem without using a manual copy of all the elements into the arraylist. Because it seems that the arraylist gets a fixed size. :-/

    L 1 Reply Last reply
    0
    • E ESTAN

      hello guys I have the following code: Dim lineArray As String() = ProcessBuffer.ToString.Split(ControlChars.Cr) Dim lineArrayList As ArrayList = ArrayList.Adapter(lineArray) I use the Adapter method to convert my array to an arraylist, what is far more easy to work in my program. Now when i want to remove a index I get this exception. Unhandled Exception: System.NotSupportedException: Collection was of a fixed size. at System.Array.System.Collections.IList.RemoveAt(Int32 index) at System.Collections.IListWrapper.RemoveAt(Int32 index) Anyone an idea how to avoid this problem without using a manual copy of all the elements into the arraylist. Because it seems that the arraylist gets a fixed size. :-/

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      try using the ArrayList(ICollection) constructor, that one copies the items for you.

      Luc Pattyn [My Articles] [Forum Guidelines]

      E 1 Reply Last reply
      0
      • L Luc Pattyn

        try using the ArrayList(ICollection) constructor, that one copies the items for you.

        Luc Pattyn [My Articles] [Forum Guidelines]

        E Offline
        E Offline
        ESTAN
        wrote on last edited by
        #3

        Thanks for the answer. I was checking ArrayList(ICollection) and I can't figure it out how it works, what i do, the same problem appears. Can you help me by putting me in the right direction? Thanks.

        L 1 Reply Last reply
        0
        • E ESTAN

          Thanks for the answer. I was checking ArrayList(ICollection) and I can't figure it out how it works, what i do, the same problem appears. Can you help me by putting me in the right direction? Thanks.

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          Hi, this is C# code that works; it prints 5 and 6

          ArrayList list;
          int\[\] arr=new int\[\]{1,2,3,4,5};
          list=new ArrayList(arr);        // the crucial line
          log("count="+list.Count);
          list.Add(6);
          log("count="+list.Count);
          

          If I am not mistaken, the crucial line translates to VB.NET as:

          list=New ArrayList(arr)
          

          :)

          Luc Pattyn [My Articles] [Forum Guidelines]

          E 1 Reply Last reply
          0
          • L Luc Pattyn

            Hi, this is C# code that works; it prints 5 and 6

            ArrayList list;
            int\[\] arr=new int\[\]{1,2,3,4,5};
            list=new ArrayList(arr);        // the crucial line
            log("count="+list.Count);
            list.Add(6);
            log("count="+list.Count);
            

            If I am not mistaken, the crucial line translates to VB.NET as:

            list=New ArrayList(arr)
            

            :)

            Luc Pattyn [My Articles] [Forum Guidelines]

            E Offline
            E Offline
            ESTAN
            wrote on last edited by
            #5

            Thanks that does the job. Now I can delete what I want without having problems.

            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