While this does seem like a very common question, I have yet to see an answer for C#. Most answers I have seen recommend using the eval() function but from what I understand, that function is exclusive to JavaScript with no visible equivalent to C#.
In my code, I thought I could use a switch statement like this:
void Update()
{
int1 = 1;
int2 = 2;
op = "+";
switch(op)
{
case "+":
return output = int1 + int2;
case "-":
return output = int1 - int2;
case "/":
return output = int1 / int2;
case "*":
return output = int1 * int2;
}
}
But that just resulted in an error:
error CS0127: Since 'EquateNumb.Update()' returns void, a return keyword must not be followed by an object expression