我怎样才能回到以前观察到的字符串

How can i go back previous observed string

示例

String context = string.Emty;

private void BtnForward_Click(object sender, RoutedEventArgs e)
{
  //First Click
  context = Abcd;
  TextboxText.Text = context; //Abcd 
  //Second Click
  TextboxText.Text = context; //new context = SADASD
  //Third Forth Fift click new string context
}

//Now how i can go back 5th string 4th string 3 2 1th string 
private void BtnBack_Click(object sender, RoutedEventArgs e)
{
  //Fift Forth Third Second First Observed string will show in the textbox
  // Reverse back previous string with sequence 
  TextBoxText.Text = context; // Will reverse/Go back in sequence 
}

我怎样才能返回字符串

甚至前进向前字符串或反向返回。我的英语不够好,无法解释,但如果您无法理解我所说的内容,请告诉我

您需要保留对以前值的引用。一种方法是保留一堆字符串,每次您点击 BtnForward_Click() 时将新值推入其中,并在您点击 BtnBack_Click() 时弹出(最近的一个)。举例如下:

    Stack context = new Stack();

    private void BtnForward_Click(object sender, RoutedEventArgs e)
    {
        // Here you would need to set the value of the Abcd based on your business logic
        context.Push(Abcd);
    }

    private void BtnBack_Click(object sender, RoutedEventArgs e)
    {
        try
        {
            TextBoxText.Text = context.Peek(); // gets the most recently entered value of the stack that has not been removed (popped)
            context.Pop();                
        }
        catch (InvalidOperationException exc)
        {
            // Nothing to go back to
        }
    }