Can I use a variable in a switch statement?

I am coding a text adventure and I have a problem. I am trying to make a switch statement that processes every required examination action, and I get this for my code:

case "examine" + string x:
    //this is a method that I made that makes sure that it is an object in the area
    bool iseobj = tut.Check(x);
    if (iseobj)
        x.examine();
    else
        Console.WriteLine("That isn't an object to examine");
    break;

How to use a variable in my instruction case? I want any line to start with "check" + (x) to trigger this case.

+4
source share
1 answer

if-else , switch. # a switch , . , :

case input.StartsWith("examine"):

if! :

if (input.StartsWith("examine"))
{
    //this is a method that I made that makes sure that it is an object in the area
    bool iseobj = tut.Check(x);
    if (iseobj)
        x.examine();
    else
        Console.WriteLine("That isn't an object to examine");
}
else if (...) // other branches here
+5

All Articles