黑马程序员之C#编程基础学习笔记:要求用户输入用户名和密码,只要不是admin,888888就一直提示要求重新输入。

--------------------------------------------------- 2345王牌技术员联盟、2345王牌技术员联盟、期待与您交流!---------------------------------------------------------


using System;

using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Test10
{
      calss Program
      {
            static void Main(string[] args)
            {
                    //要求用户输入用户名和密码,只要不是admin,888888就一直提示要求重新输入。
                    Console.WriteLine("请输入用户名");
                    string username = Console.ReadLine();
                    Console.WriteLine("请输入密码");
                    string password= Console.ReadLine();
                    while( username != "admin" || password != "888888")
                    {
                           Console.WriteLine("用户名,密码错误");
                           Console.WriteLine("请重新输入用户名");
                           username = Console.ReadLine();//在这里重新赋值的username在while可以用,因为是执行完了                                                                                   // username = Console.ReadLine()又去while( username != "admin" ||                                                                         //password != "888888")
                           Console.WriteLine("请重新输入密码");
                           password= Console.ReadLine();
                    }
                    Console.ReadKey();
            }
      }

}


--------------------------------------------------- 2345王牌技术员联盟、2345王牌技术员联盟、期待与您交流!---------------------------------------------------------

你可能感兴趣的:(黑马程序员C#学习笔记)