sonic_eel

Hi,

In Delphi you can assign one object to another using code like this:

myObject.Assign(myOtherObject);

I may have missed something but I can't really see how to do this in C# so I have been making a method in my class something like this:

class MyClass

public Int32 anumber;
public Int32 bnumber;

public void Assign(MyClass myclass)
{
this.anumber = myclass.anumber;
this.bnumber = myclass.bnumber;
}

....................

I can't use:
myClass2 = myClass1;
because I do not want to reference myClass1 I just want to make an exact replica of it.

This is probably a really silly question, In fact I know it is... But still may someone please give me a little assistance on this one

Thanks, Lee.



Re: Visual C# General Assigning properties of one object to another

anomolous

Take a look at the MemberwiseClone method of Object and the ICloneable interface. I think these are as close as you will get to the Assign() functionality.