簡體   English   中英

多個 IF 語句不能相互配合

[英]Multiple IF Statements Not working with each other

using System;

namespace HelloWorld
{
    class MainClass
    {
        // Entry Point For Program
        public static void Main(string[] args)
        {
            Console.WriteLine("Enter your name:");

            String Name = Console.ReadLine();

            Console.WriteLine($"Thank you, so your name is {Name}?:");
            if (Console.ReadLine() == "Yes" || Console.ReadLine() == "yes")
            {
                Console.WriteLine($"So I will be calling you {Name}");
            }
            
            if(Console.ReadLine() == "No" || Console.ReadLine() == "no")
            {
                Console.WriteLine("Then Enter your Name again:");
                String Name2 = Console.ReadLine();
                Console.WriteLine($"So your name this time is {Name}");
            }
        }
    }
}

您需要調用 ReadLine 一次

        Console.WriteLine($"Thank you, so your name is {Name}?:");
        var response = Console.ReadLine();
        if (response == "Yes" || response == "yes")
        {
            Console.WriteLine($"So I will be calling you {Name}");
        }

甚至

        Console.WriteLine($"Thank you, so your name is {Name}?:");
        var response = Console.ReadLine();
        if (response.ToLower() == "yes")
        {
            Console.WriteLine($"So I will be calling you {Name}");
        }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM