I'm writing an undo and redo for my notepad. This is my undo and redo code and I have a System.IndexOutOfRangeException
exception, how can I fix this? Is there another way to do this?
string[] temp = new string[100];
int index;
int currentpostion;
public Undo()
{
index = 0;
currentpostion = 0;
}
public void Set_Text(string s)
{
temp[index] = s;
currentpostion = index;
++index;
}
public string UndoCons()
{
if (currentpostion > 0)
{
return temp[--currentpostion];
}
return null;
}
public string RedoCosns()
{
if (currentpostion < index)
{
return temp[++currentpostion];
}
return null;
}
}
This error occurs when the array is full. What can I do? Can anyone improve this algorithm?