I'm trying to build a calculator by just entering the operation in 1 line. I got stuck when i try to split the input and use a foreach loop
string input = "28 + 2";
string[] array = input.Split();
foreach(string value in array)
{
// trying to assign the first value of foreach to 'num1'
int num1 = [0];
}
what I need here is how to assign the first and third value to a variable so I can use it to build the calculator but, I think I use the wrong way to assign it
note: the split funtion is working. if i do this:
string input = "28 + 2";
string[] array = input.Split();
foreach(string value in array)
{
Console.WriteLine(value);
}
I get the output 28, +, 2
I will use this function to not just add two numbers but divide, multiply and subtract them. So the answer i need here is how to actually assign split values to a variable not split the string