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. How can I convert an object to ArrayList

How can I convert an object to ArrayList

Scheduled Pinned Locked Moved C#
helpdata-structurestutorialquestion
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.
  • N Offline
    N Offline
    Naveed727
    wrote on last edited by
    #1

    I want to convert object to Array List but stuck how to do. Actually I am doing this because I am passing argument of an array this array is contains some panels. When I pass these panels to another form it copy the references of panels. Any thing changes in child form(in panels ) affect the father form panels. Here is the code.

    object obj = array.Clone();

    Now the object become object array but there is no technique to convert this obj to object[]. If you have any suggestion to overcome my problem to not copy the references of the array(panels) . You are most welcome if you give any suggestion.

    N S 2 Replies Last reply
    0
    • N Naveed727

      I want to convert object to Array List but stuck how to do. Actually I am doing this because I am passing argument of an array this array is contains some panels. When I pass these panels to another form it copy the references of panels. Any thing changes in child form(in panels ) affect the father form panels. Here is the code.

      object obj = array.Clone();

      Now the object become object array but there is no technique to convert this obj to object[]. If you have any suggestion to overcome my problem to not copy the references of the array(panels) . You are most welcome if you give any suggestion.

      N Offline
      N Offline
      N a v a n e e t h
      wrote on last edited by
      #2

      Naveed khan nido wrote:

      but there is no technique to convert this obj to object[].

      object[] obj = (object[])obj

      Navaneeth How to use google | Ask smart questions

      N 1 Reply Last reply
      0
      • N Naveed727

        I want to convert object to Array List but stuck how to do. Actually I am doing this because I am passing argument of an array this array is contains some panels. When I pass these panels to another form it copy the references of panels. Any thing changes in child form(in panels ) affect the father form panels. Here is the code.

        object obj = array.Clone();

        Now the object become object array but there is no technique to convert this obj to object[]. If you have any suggestion to overcome my problem to not copy the references of the array(panels) . You are most welcome if you give any suggestion.

        S Offline
        S Offline
        S Senthil Kumar
        wrote on last edited by
        #3

        Cloning the array won't help solve your problem - the array will get cloned, not the elements in the array. The panel objects will still be shared. You can deep clone i.e. clone the panels themselves. What are you trying to do though?

        Regards Senthil [MVP - Visual C#] _____________________________ My Home Page |My Blog | My Articles | My Flickr | WinMacro

        N 1 Reply Last reply
        0
        • S S Senthil Kumar

          Cloning the array won't help solve your problem - the array will get cloned, not the elements in the array. The panel objects will still be shared. You can deep clone i.e. clone the panels themselves. What are you trying to do though?

          Regards Senthil [MVP - Visual C#] _____________________________ My Home Page |My Blog | My Articles | My Flickr | WinMacro

          N Offline
          N Offline
          Naveed727
          wrote on last edited by
          #4

          yes you are right. It is still coping the references. The thing I am doing is that I have an array of panels and these panels have some Labels and Picture Boxes. Now I am going to create an another form and need a copy of these panels and the objects that panels contains. In another form it will further changes(i,e Labels or Pic Boxes) that changes should not made to Parent Form. So what should I do. Can you give me an example of deep clone. How should solve my problem. thanks for reply.

          S H 2 Replies Last reply
          0
          • N N a v a n e e t h

            Naveed khan nido wrote:

            but there is no technique to convert this obj to object[].

            object[] obj = (object[])obj

            Navaneeth How to use google | Ask smart questions

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

            Thanks for giving the technique to convert object to object array. But after cloning I have facing the same problem. Can you help me regards this. Thanks

            1 Reply Last reply
            0
            • N Naveed727

              yes you are right. It is still coping the references. The thing I am doing is that I have an array of panels and these panels have some Labels and Picture Boxes. Now I am going to create an another form and need a copy of these panels and the objects that panels contains. In another form it will further changes(i,e Labels or Pic Boxes) that changes should not made to Parent Form. So what should I do. Can you give me an example of deep clone. How should solve my problem. thanks for reply.

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

              You could write a function that will do the deep clone for you...

              It's not a bug, it's a feature! Me in Softwareland.

              1 Reply Last reply
              0
              • N Naveed727

                yes you are right. It is still coping the references. The thing I am doing is that I have an array of panels and these panels have some Labels and Picture Boxes. Now I am going to create an another form and need a copy of these panels and the objects that panels contains. In another form it will further changes(i,e Labels or Pic Boxes) that changes should not made to Parent Form. So what should I do. Can you give me an example of deep clone. How should solve my problem. thanks for reply.

                H Offline
                H Offline
                Henry Minute
                wrote on last edited by
                #7

                Just a thought. You might be better off converting these panels into custom controls. That way you can create the second form by just dropping the custom control in. Then create a class or struct with fields for the information from form 1, instantiate the class/struct with the data from form 1 and pass it to second form whre data gets inserted into custom control.

                Henry Minute If you open a can of worms, any viable solution *MUST* involve a larger can.

                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