void Main() { Product product = new Product{Name="A"}; Director director = new Director(); director.Memento=product.Save(); product.Load(director.Memento); } class Product{ public string Name { get; set; } public Memento Save(){ return new Memento{Name=Name}; } public void Load(Memento m){ Name=m.Name; } } class Memento{ public string Name { get; set; } } class Director{ public Memento Memento { get; set; } }
时间: 2024-11-29 04:18:15