小编Sim*_*ght的帖子

如果,不等于和/或帮助(不确定哪个)

我试图询问输入是否是合法的数值变量.我已经尝试过这种方式(它显示错误的输出,如图所示),使用==和else(其中说其他错误)并且不知道为什么它不起作用.任何建议或其他尝试这样做的方式将非常感激.

static void start()
{
    // start of broken code

    Console.WriteLine("Please select a variable type");
    string selection = Console.ReadLine();
    if ((selection != "short") || (selection != "ushort") || (selection != "int") || (selection != "uint") || (selection != "byte") || (selection != "long") || (selection != "ulong"));
    {
        Console.WriteLine("That is not a correct form of variable");
        Console.WriteLine("Let's try this again");
        start();
    }

    // end of broken code

    Console.WriteLine("You selected ", selection);
    Console.WriteLine("Is this correct? (Y/N)");
    string sure = Console.ReadLine();
    if …
Run Code Online (Sandbox Code Playgroud)

c#

3
推荐指数
1
解决办法
85
查看次数

标签 统计

c# ×1