Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在控制台应用程序中添加c#登录尝试循环?_C#_Loops_Login Attempts - Fatal编程技术网

如何在控制台应用程序中添加c#登录尝试循环?

如何在控制台应用程序中添加c#登录尝试循环?,c#,loops,login-attempts,C#,Loops,Login Attempts,我不熟悉这种语言,我尝试过一些东西,但不知道如何设置一个登录循环来使用最多3次的登录尝试。有人能帮我吗 static void Main(string[] args) { Console.WriteLine("Status: " + status.Onaangemeld); Console.WriteLine("Welkom, typ hieronder het gebruikersnaam:"); string Naam = C

我不熟悉这种语言,我尝试过一些东西,但不知道如何设置一个登录循环来使用最多3次的登录尝试。有人能帮我吗

    static void Main(string[] args)
    {

        Console.WriteLine("Status: " + status.Onaangemeld);
        Console.WriteLine("Welkom, typ hieronder het gebruikersnaam:");
        string Naam = Console.ReadLine();

        Console.WriteLine("Vul hieronder het wachtwoord in:");
        string Wachtwoord = Console.ReadLine();

        if (Naam == "gebruiker" && Wachtwoord == "SHARPSOUND")
        {
            Console.Clear();
            Console.WriteLine("Status: " + status.Ingelogd);
            Console.WriteLine("Welkom bij SoundSharp {0}!", Naam);
            Console.ReadLine();
        }

        else
        Console.Clear();
        Console.WriteLine("Helaas, gebruikersnaam of wachtwoord niet correct.");

    }
  }
static void Main(字符串[]args)
{

对于(int i=0;i您应该添加for循环以获得最大尝试次数。 以下内容可供参考


您可以相应地使用for循环,无论您希望用户只输入密码还是同时输入用户名和密码

为什么不递归

    class Program
    {
        const int MaxAttempt = 3;
        static int currentAttempt = 0;

        static void Main(string[] args)
        {
            if (MaxAttempt == currentAttempt)
            {
                Console.WriteLine("You have reached maximum try .. please come after some time");
                Console.ReadLine();
                Environment.Exit(0);
            }

            currentAttempt++;

            Console.WriteLine("Status: " + status.Onaangemeld);
            Console.WriteLine("Welkom, typ hieronder het gebruikersnaam:");
            string Naam = Console.ReadLine();

            Console.WriteLine("Vul hieronder het wachtwoord in:");
            string Wachtwoord = Console.ReadLine();

            if (Naam != "gebruiker" || Wachtwoord != "SHARPSOUND")
            {
                Console.Clear();
                Console.WriteLine("Helaas, gebruikersnaam of wachtwoord niet correct. Please try again");
                Console.ReadLine();
                Console.Clear();
                Main(args);
            }


            Console.Clear();
            Console.WriteLine("Status: " + status.Ingelogd);
            Console.WriteLine("Welkom bij SoundSharp {0}!", Naam);
            Console.ReadLine();


        }
    }

您应该添加一些内容来“记住”登录到bedankt@JeroenvanLangen的用户
    class Program
    {
        const int MaxAttempt = 3;
        static int currentAttempt = 0;

        static void Main(string[] args)
        {
            if (MaxAttempt == currentAttempt)
            {
                Console.WriteLine("You have reached maximum try .. please come after some time");
                Console.ReadLine();
                Environment.Exit(0);
            }

            currentAttempt++;

            Console.WriteLine("Status: " + status.Onaangemeld);
            Console.WriteLine("Welkom, typ hieronder het gebruikersnaam:");
            string Naam = Console.ReadLine();

            Console.WriteLine("Vul hieronder het wachtwoord in:");
            string Wachtwoord = Console.ReadLine();

            if (Naam != "gebruiker" || Wachtwoord != "SHARPSOUND")
            {
                Console.Clear();
                Console.WriteLine("Helaas, gebruikersnaam of wachtwoord niet correct. Please try again");
                Console.ReadLine();
                Console.Clear();
                Main(args);
            }


            Console.Clear();
            Console.WriteLine("Status: " + status.Ingelogd);
            Console.WriteLine("Welkom bij SoundSharp {0}!", Naam);
            Console.ReadLine();


        }
    }