using System.Collections.Generic;
public EditorState(string content) {
public string Content {get; set; }
public EditorState createState() {
return new EditorState(Content);
public void restore(EditorState state) {
private List<EditorState> states = new List<EditorState>();
public void push(EditorState state) {
public EditorState pop() {
var lastIndex = states.Count - 1;
var lastState = states[lastIndex];
states.Remove(lastState);
public static void Main()
var editor = new Editor();
var history = new History();
editor.Content = "hello";
history.push(editor.createState());
editor.Content = "hello world";
history.push(editor.createState());
editor.Content = "hello world design patterns";
editor.restore(history.pop());
Console.WriteLine(editor.Content);