How Can i Copy Object?!
-
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?
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
-
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
-
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
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 implementICloneable
. Adding it to theForm1
class will not help, it only demands that you provide an implementation for theForm1
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
-
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 implementICloneable
. Adding it to theForm1
class will not help, it only demands that you provide an implementation for theForm1
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
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