判断用户和密码 如果输入一个值则直接报错
Console.WriteLine("请输入用户名和密码"); string one = Console.ReadLine(); //获取了当前的数据 string two = Convert.ToString(one); int cons=two.IndexOf(" "); if (cons > 0) { string var1 = two.Substring(0, cons); string var2 = two.Substring(cons, two.Length - cons - 1); if (var1.ToUpper() == "ADMIN" && var2.ToUpper() == "MYPASS") { Console.WriteLine("登陆成功"); } else { Console.WriteLine("登录失败"); } } else { Console.WriteLine("必须输入两个字符串,且以空格隔开"); Console.WriteLine("按任意键退出"); } Console.ReadKey();
时间: 2024-10-11 04:24:19