首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用ReadKey拥有多个“密码”?

使用ReadKey拥有多个“密码”?
EN

Stack Overflow用户
提问于 2016-07-19 15:30:11
回答 1查看 32关注 0票数 0

所以我只是在使用控制台创建一个小程序,它将根据您输入的“密码”显示内容。因此,当您输入密码POKEMON时,它会将您带到数据库。但是我想这样,如果你输入类似密码的东西,那么它会带你到另一个数据库。我不知道怎么做,我希望这会像说“如果他们输入口袋妖怪,在这里,如果他们输入密码,在这里”,但我有真正的麻烦。感谢你的帮助。

代码语言:javascript
复制
namespace Films
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello Jake. Security check: Please type the security code for a database.");
            while (Console.ReadKey().Key != ConsoleKey.P) {}
            while (Console.ReadKey().Key != ConsoleKey.O) {}
            while (Console.ReadKey().Key != ConsoleKey.K) {}
            while (Console.ReadKey().Key != ConsoleKey.E) {}
            while (Console.ReadKey().Key != ConsoleKey.M) {}
            while (Console.ReadKey().Key != ConsoleKey.O) {}
            while (Console.ReadKey().Key != ConsoleKey.N) {}
            { 
                Console.WriteLine("\n Passcode entered successfully.");
                while (Console.ReadKey().Key != ConsoleKey.O) { }
                while (Console.ReadKey().Key != ConsoleKey.K) { }
                {
                    Console.WriteLine("\n \n                       Loading Database");
                    Console.WriteLine("\n");
                    Console.WriteLine("Test");
                    Console.ReadKey();
                }
            }
        }
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-07-19 15:34:53

有一个叫做Console.ReadLine()的方法

ReadLine方法从标准输入流中读取一行。 如果标准输入设备是键盘,则ReadLine方法会阻塞,直到用户按下Enter键。

在你的情况下,你会像这样使用它:

代码语言:javascript
复制
Console.WriteLine("Hello Jake. Security check: Please type the security code for a database.");

// This will read all the characters until the user presses Enter
string password = Console.ReadLine();

switch (password)
{
    case "POKEMON":
    {
        // Load some database
        break;
    }
    case "PASSWORD":
    {
        // Load another database
        break;
    }
    default:
    {
        Console.WriteLine("Invalid password");
    }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38462815

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档