(C# Visual Studio) Saving input and showing history of inputs

Viewed 30

Amateur here making a C# calculator in visual studio and want to save inputs as 'operand1' and 'operand2' such that I can display the history of inputs/calculations. Example of my first thought:

private void twoBtn_Click(object sender, EventArgs e)
        {
            if (txtBox.Text == "0")
            {
                txtBox.Text = "2";
            }
            else
            {
                txtBox.Text += "2";
            }
        }

The issue is that it simply adds that to the text box, which is fine for calculations, but I have no way of retrieving that input data after it's cleared.

I've tried setting it up like this:

private void oneBtn_Click(object sender, EventArgs e)
        {
            if (operand1 == null)
            {
                operand1 = 1;
                txtBox.Text = operand1.ToString();
                return;
                
            }
            if (operand2 != null) return;
            operand2 = 1;
            txtBox.Text = operand2.ToString();
        }

However, the issue here is that I cannot seem to input an operand which is more than 1 digit, making the only possible operands numbers 1-9. I understand I'm very new to the language and coding in general and would greatly appreciate anyone's insight as to what I'm missing!

0 Answers
Related