小编Fir*_*175的帖子

我可以在switch语句中使用变量吗?

我正在编写基于文本的冒险,并且遇到了问题.我正在尝试创建一个switch语句案例来处理您想要的每个考试操作,并且到目前为止我的代码正在获取此代码:

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;
Run Code Online (Sandbox Code Playgroud)

如何在case语句中使用变量?我想要任何以"examine"+(x)开头的字符串来触发这个案例.

.net c# console-application switch-statement

4
推荐指数
1
解决办法
519
查看次数

标签 统计

.net ×1

c# ×1

console-application ×1

switch-statement ×1