Skip to content

Instantly share code, notes, and snippets.

@xmfcx
Last active August 29, 2015 14:23
Show Gist options
  • Save xmfcx/be93511b955d439c54cb to your computer and use it in GitHub Desktop.
Save xmfcx/be93511b955d439c54cb to your computer and use it in GitHub Desktop.
I want Class to remember the old values but it updates them :(
class TheClass
{
public int Val1;
public TheClass Old;
}
class Program
{
static void Main(string[] args)
{
TheClass aClass = new TheClass();
aClass.Val1 = 5;
aClass.Old = aClass;
aClass.Val1 = 10;
Console.WriteLine(aClass.Old.Val1);
//Prints 10, not 5:(
Console.ReadKey();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment