I'm writing a text adventure for a course in the Visual Studio C# console, and decided to use the switch statement instead of a chain of if-elses due to how useful goto case can be (it has worked remarkably so far). I know that each case within the switch itself has to be a constant but I'm wondering if this extends to using goto case as well. For example I have:
switch (location)
{
case 1:
break;
case 2:
break;
case 3:
break;
//I have 10 cases, each representing a location such as "Orc Cave", I just cut it down for brevity
default:
break;
}
I would like to be able to input an integer variable and then go to that integer, I have the following to accomplish that:
string travel2 = Console.ReadLine();//inputs a integer representing each location
int travel2A = Convert.ToInt32(travel2);
if (1<=travel2A && travel2A<=10)
{
goto case(travel2A);
}
else{
goto case(2);//current location
}
Everything works fine yet there is a "A constant value is expected" warning underlinining the case(travel2A). Is it possible to make goto case input a variable with some tweaks or is that just a limitation of the switch statement? If it's the latter I can just do a chain of if-elses but imputting a variable is more convenient in my opinion. Any help on this is greatly appreciated! Thank you!