How to use undo redo in my code? | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 11

How to use undo redo in my code?

Can someone show me with simplest example. Example : 2+1; 2+3 ... I prefer c#. You are welcome with java and c++.

13th Apr 2017, 12:06 PM
Yasar Curci
Yasar Curci - avatar
1 ответ
+ 3
Try something similiar like: public class Rectangle { private Stack _stack; private int height = 10; private int width = 10; public void BeginEdit() { if (_stack == null) { _stack = new Stack(); } Hashtable state = new Hashtable(4); state["height"] = height; state["width"] = height; _stack.Push(state); } public void CommitEdit() { Hashtable editState = (Hashtable) _stack.Pop(); editState.Clear(); editState = null; if (_stateStack.Count == 0) { _stateStack = null; } } public void RollbackEdit() { Type type = this.GetType(); Hashtable editState = (Hashtable)_stateStack.Pop(); this.height = (int) editState["height"]; this.width = (int) editState["width"]; editState.Clear(); editState = null; if (_stateStack.Count == 0) { _stateStack = null; } } }
14th Apr 2017, 3:33 AM
Square Weber Interactive
Square Weber Interactive - avatar