Original Post
Ok, a strange question, for some reason I have never come across this before, so never had to figure out how to do it. Say I have the following. So what I want to do is assign by value instead of by reference so class1 gets the value of class2 but does not point to the same object. You might wonder why I am just not using structs. Well the classes I am uses inherit from a base class that has lots and lots of code in it that would have to be duplicated if I changed it to struct because you can't inherit. Any ideas, I just want to do class1 = class2 assignments because this is going to happen a lot and I don't want other people to get confused have to clone or copy it to get it to work right. theTroll
public class MyClass
{
public int Value;
public MyClass(int value) {Value = value}
}
MyClass class1 = new MyClass(27);
MyClass class2 = new MyClass(84);
class1 = class2; // now class1 and class2 both point to the same object so value = 84
class2.Value = 43; // so now both are 43.