[英]If and else if statements C#
嗨,當我輸入“是”或“否” /“否”時,它什么都不做?它應該做什么?我做錯了什么?
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Username:");
String user = Console.ReadLine();
Console.WriteLine("Password:");
String Pass = Console.ReadLine();
Console.WriteLine("Are You Sure Your User: " + user + " And Pass: " + Pass + " is correct? Yes/No");
Console.ReadLine();
if (Console.ReadLine() == "Yes" || Console.ReadLine() == "yes")
{
Console.WriteLine("You May now close this");
}
else if(Console.ReadLine() == "No" || Console.ReadLine() == "no")
{
Console.WriteLine("Pleas Press enter");
System.Diagnostics.Process.Start(Environment.GetCommandLineArgs()[0], Environment.GetCommandLineArgs().Length > 1 ? string.Join(" ", Environment.GetCommandLineArgs().Skip(1)) : null);
}
}
}
您要求兩次用戶輸入。 第一個Console.ReadLine();
是您要輸入“是”或“否”的內容,但是您的if
/ else if
語句再次要求輸入。
Console.WriteLine("Are You Sure Your User: " + user + " And Pass: " + Pass + " is correct? Yes/No");
var input = Console.ReadLine();
if (input == "Yes" || input == "yes")
{
Console.WriteLine("You May now close this");
}
else if(input == "No" || input == "no")
{
Console.WriteLine("Pleas Press enter");
System.Diagnostics.Process.Start(Environment.GetCommandLineArgs()[0], Environment.GetCommandLineArgs().Length > 1 ? string.Join(" ", Environment.GetCommandLineArgs().Skip(1)) : null);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.