using System.Collections.Generic;
public string ActionName { get; set; }
public object ActionData { get; set; }
public class UndoRedoManager
private Stack<ActionDTO> undoStack = new Stack<ActionDTO>();
private Stack<ActionDTO> redoStack = new Stack<ActionDTO>();
public void ExecuteAction(ActionDTO action)
Console.WriteLine($"Action executed: {action.ActionName}");
ActionDTO action = undoStack.Pop();
Console.WriteLine($"Action undone: {action.ActionName}");
Console.WriteLine("No actions to undo.");
ActionDTO action = redoStack.Pop();
Console.WriteLine($"Action redone: {action.ActionName}");
Console.WriteLine("No actions to redo.");
public ActionDTO PeekUndo()
return undoStack.Count > 0 ? undoStack.Peek() : null;
public ActionDTO PeekRedo()
return redoStack.Count > 0 ? redoStack.Peek() : null;
public bool SearchUndo(string actionName)
foreach (var action in undoStack)
if (action.ActionName == actionName)
public bool SearchRedo(string actionName)
foreach (var action in redoStack)
if (action.ActionName == actionName)
static void Main(string[] args)
UndoRedoManager manager = new UndoRedoManager();
manager.ExecuteAction(new ActionDTO { ActionName = "Action1", ActionData = "Data1" });
manager.ExecuteAction(new ActionDTO { ActionName = "Action2", ActionData = "Data2" });
ActionDTO topUndoAction = manager.PeekUndo();
Console.WriteLine($"Top Undo Action: {topUndoAction?.ActionName}");
bool found = manager.SearchUndo("Action1");
Console.WriteLine($"Action1 found in undo stack: {found}");