public class Memento
{
private string _msg;
public Memento(string msg)
{
_msg = msg;
}
public string GetText()
{
return _msg;
}
}
public class Notepad
{
private string _msg;
public Memento SetMsg(string msg)
{
Memento m = new Memento(msg);
_msg = msg;
return m;
}
public string GetMsg()
{
return _msg;
}
public void Undo(Memento previousState)
{
if (previousState != null)
{
_msg = previousState.GetText();
}
else
{
_msg = "";
}
}
}
class Program
{
static void Main(string[] args)
{
IList<Memento> undos = new List<Memento>();
Notepad notepad = new Notepad();
Memento undo;
undo = notepad.SetMsg("Hello");
undos.Add(undo);
undo = notepad.SetMsg("World");
undos.Add(undo);
Console.WriteLine("进入Nodepad查看信息");
Console.WriteLine(notepad.GetMsg());
Console.WriteLine("1、接着执行一个回退操作");
notepad.Undo(undos[0]);
Console.WriteLine("回退操作以后查看信息");
Console.WriteLine(notepad.GetMsg());
Console.WriteLine("2、再执行一个回退操作");
notepad.Undo(null);
Console.WriteLine("回退操作以后再查看信息");
Console.WriteLine(notepad.GetMsg());
Console.ReadKey();
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有