public void MementoDemo2() { var originator2 = new Originator2(); originator2.State = "s1"; originator2.CreateMemento(); originator2.State = "s2"; Console.WriteLine($"当前状态:{originator2.State}"); Console.WriteLine("------ 恢复上一个状态 ------"); originator2.RestoreMemento(); Console.WriteLine($"当前状态:{originator2.State}"); }
public void CreateMemento() { _backup = this.Copy(); }