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. Static Arraylist?

Static Arraylist?

Scheduled Pinned Locked Moved C#
data-structureshelpquestion
7 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.
  • S Offline
    S Offline
    SherKar
    wrote on last edited by
    #1

    hi i have a problem accessin the arraylist i made in a form by another form as i had to make static array and when i put data in it in for loop it just saves the last data the loop put what can i do? thanx

    L D H 3 Replies Last reply
    0
    • S SherKar

      hi i have a problem accessin the arraylist i made in a form by another form as i had to make static array and when i put data in it in for loop it just saves the last data the loop put what can i do? thanx

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      A static array exists only once. Anything you do to it will reflect elsewhere. Make it non static so that each instance has it's own array. If you are using a form, try calling the array from a non static method. You are probably trying to read it from main. :) Cata

      S 1 Reply Last reply
      0
      • L Lost User

        A static array exists only once. Anything you do to it will reflect elsewhere. Make it non static so that each instance has it's own array. If you are using a form, try calling the array from a non static method. You are probably trying to read it from main. :) Cata

        S Offline
        S Offline
        SherKar
        wrote on last edited by
        #3

        thanx but i don't need that each instance have its own array as i need the data from the array that i put in the 1rst form in the second to do changes in it then i need the changed array in the 3rd form

        A 1 Reply Last reply
        0
        • S SherKar

          thanx but i don't need that each instance have its own array as i need the data from the array that i put in the 1rst form in the second to do changes in it then i need the changed array in the 3rd form

          A Offline
          A Offline
          Anonymous
          wrote on last edited by
          #4

          Ok, you could always use the array.clone() method, to copy it into a local array, and then apply the changes there. THEN forward the modified array. This will keep the origional array unchanged, but enable you to manipulate a modified version.

          1 Reply Last reply
          0
          • S SherKar

            hi i have a problem accessin the arraylist i made in a form by another form as i had to make static array and when i put data in it in for loop it just saves the last data the loop put what can i do? thanx

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

            You might want to post some code samples of your array and what your doing to modify it. RageInTheMachine9532

            S 1 Reply Last reply
            0
            • D Dave Kreskowiak

              You might want to post some code samples of your array and what your doing to modify it. RageInTheMachine9532

              S Offline
              S Offline
              SherKar
              wrote on last edited by
              #6

              ((Offices)(OfficesNames[i])).OfficeAtt= new ArrayList(AllNodes); Offices ->class OfficesNames->array of object of offices officeAtt->arraylist have object of another class called attributes this line of code to intialize the arraylist of attributes of each office for(int i=0;i

              1 Reply Last reply
              0
              • S SherKar

                hi i have a problem accessin the arraylist i made in a form by another form as i had to make static array and when i put data in it in for loop it just saves the last data the loop put what can i do? thanx

                H Offline
                H Offline
                Heath Stewart
                wrote on last edited by
                #7

                When you enumerate a collection or list (anything that implements IEnumerable, it is documented behavior to throw an exception. This is to ensure that changes to the list or collection aren't skipped when looping. You can either clone the list or collection or use an iterative loop (for, as opposed to foreach).

                Microsoft MVP, Visual C# My Articles

                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