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 Copy Object?!

How Can i Copy Object?!

Scheduled Pinned Locked Moved C#
questioncsharphelp
5 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.
  • A Offline
    A Offline
    Admin887
    wrote on last edited by
    #1

    My Code in C#: Object o1=new Object(); Object o2; How can i copy the o2 object to be exactly like o1( no a reference. o2=o1 is reference). i tried o2.copy(o1) or something like this but the method "copy" does not exist X| ; Can you help me?

    K 1 Reply Last reply
    0
    • A Admin887

      My Code in C#: Object o1=new Object(); Object o2; How can i copy the o2 object to be exactly like o1( no a reference. o2=o1 is reference). i tried o2.copy(o1) or something like this but the method "copy" does not exist X| ; Can you help me?

      K Offline
      K Offline
      Karthik Kalyanasundaram
      wrote on last edited by
      #2

      You can create an exact copy of the object using Clone() method if that type implements ICloneable interface

      Do more work Make more mistakes Learn more things

      A 1 Reply Last reply
      0
      • K Karthik Kalyanasundaram

        You can create an exact copy of the object using Clone() method if that type implements ICloneable interface

        Do more work Make more mistakes Learn more things

        A Offline
        A Offline
        Admin887
        wrote on last edited by
        #3

        by the way, i am using Visual Studio 2008. what do you mean type? which type? i added "ICloneable" here:

        public partial class Form1 : Form,ICloneable
        {
        Object o1=new Object();
        Object o2;

         // o2.clone() does not exist:mad:
        

        }

        Thanks you

        C 1 Reply Last reply
        0
        • A Admin887

          by the way, i am using Visual Studio 2008. what do you mean type? which type? i added "ICloneable" here:

          public partial class Form1 : Form,ICloneable
          {
          Object o1=new Object();
          Object o2;

           // o2.clone() does not exist:mad:
          

          }

          Thanks you

          C Offline
          C Offline
          Colin Angus Mackay
          wrote on last edited by
          #4

          Admin887 wrote:

          // o2.clone() does not exist :mad:

          It doesn't help if you appear to be angry with the person that tried to help you. Especially, when it seems you have misunderstood that assistance. You cannot clone a System.Object because it does not implement ICloneable. Adding it to the Form1 class will not help, it only demands that you provide an implementation for the Form1 class.

          Admin887 wrote:

          what do you mean type? which type?

          A "type" in .NET can be a class, a struct, an enum, and so on. The "type" the person was referring to was the type of the object which you are trying to clone. You can only add ICloneable to types that you create. You cannot add it to existing types. Now, what do you really want to do? Creating a System.Object is generally not a very useful thing to do.

          Recent blog posts: * Event Organisation (Feedback) * LINQ to XML (part 4) * Scottish Developers June Newsletter My Blog

          A 1 Reply Last reply
          0
          • C Colin Angus Mackay

            Admin887 wrote:

            // o2.clone() does not exist :mad:

            It doesn't help if you appear to be angry with the person that tried to help you. Especially, when it seems you have misunderstood that assistance. You cannot clone a System.Object because it does not implement ICloneable. Adding it to the Form1 class will not help, it only demands that you provide an implementation for the Form1 class.

            Admin887 wrote:

            what do you mean type? which type?

            A "type" in .NET can be a class, a struct, an enum, and so on. The "type" the person was referring to was the type of the object which you are trying to clone. You can only add ICloneable to types that you create. You cannot add it to existing types. Now, what do you really want to do? Creating a System.Object is generally not a very useful thing to do.

            Recent blog posts: * Event Organisation (Feedback) * LINQ to XML (part 4) * Scottish Developers June Newsletter My Blog

            A Offline
            A Offline
            Admin887
            wrote on last edited by
            #5

            First of all, i am very sorry, really.unintentionally i added this smile. I do not mean it. i am very nice guy :D And now to the question: I created a GroupBox(groupBox1) that contains textBox and buttons(i created this with the design option on the Form). i want to create a new Tab(only with code without designing) that contains gruopBox(g) exactly like groupbox1.

            GroupBox g = new GroupBox();
            // g=groupbox1 will be Reference;
            // i want that 'g' will be like 'groupbox1'

            Thank you for your attention G.

            modified on Sunday, June 29, 2008 5:30 AM

            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