This being C# and highly object-oriented you are doing yourself a disservice by treating it as script and having all your code under Main().
In C# think about a data model. How do I define objects that hold the information I want. In this example I want to make a calculator, and so I design a class that holds the calculator result, and can perform the basic operations to this result.
Data Model
public class Calculator
{
public Calculator()
{
Result = 0;
}
/// <summary>
/// Hold the result of the calculations
/// </summary>
public int Result { get; set; }
/// <summary>
/// Adds a number to the result
/// </summary>
/// <param name="x">The number.</param>
public void Add(int x)
{
Result += x;
}
/// <summary>
/// Subtracts a number from the result
/// </summary>
/// <param name="x">The number.</param>
public void Subtract(int x)
{
Result -= x;
}
/// <summary>
/// Multiplies the result with a number
/// </summary>
/// <param name="x">The number.</param>
public void Multiply(int x)
{
Result *= x;
}
/// <summary>
/// Divides the result with a number
/// </summary>
/// <param name="x">The number.</param>
public void Divide(int x)
{
Result /= x;
}
}
The above is pretty straightforward. There are four methods that modify the result, and one constructor to initialize the data.
Program
The actual program should then define and act on the data model. I chose to have an infinite loop when the user can select the next action, and can exit the loop by just pressing enter
class Program
{
static void Main(string[] args)
{
// calculator object iniialized
Calculator calculator = new Calculator();
// Inifinte loop
while (true)
{
// Report the caclulator result
Console.WriteLine($"Result = {calculator.Result}");
Console.WriteLine();
Console.WriteLine("Select Operation:");
Console.WriteLine(" [1] Addition");
Console.WriteLine(" [2] Subtraction");
Console.WriteLine(" [3] Multiplication");
Console.WriteLine(" [4] Division");
Console.WriteLine(" [ENTER] Exit");
string input = Console.ReadLine();
// Check if user entered a number
if (int.TryParse(input, out int operation))
{
Console.WriteLine("Enter value:");
input = Console.ReadLine();
// Check if user enter a value
if (int.TryParse(input, out int x))
{
// Perform the operation
switch (operation)
{
case 1:
calculator.Add(x);
break;
case 2:
calculator.Subtract(x);
break;
case 3:
calculator.Multiply(x);
break;
case 4:
calculator.Divide(x);
break;
default:
Console.WriteLine("Unknown Operation");
break;
}
}
}
else // user did not enter a number
{
break; // end the while loop
}
}
}
}
Inside the loop, the last result is displayed and the user selects the operation 1-4 and types a number to use. Then use the calculator methods to do the math. For example calculator.Add(x); adds the number stored in x to the result.