本文介绍了如果..其他问题,请帮忙的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

static void Main(string[] args)
       { string continue1 = "yes";



           while (continue1 == "yes")

           {
               Console.WriteLine("your name?:");
               string jmeno = Console.ReadLine();
               Console.WriteLine(jmeno + " is the best!");

               Console.WriteLine("New name? (yes/no)");
               if (continue1 == "yes")

                   continue1 = Console.ReadLine();


               // the following doesn´t work

              else Console.WriteLine("What a shame :(");

           }
           Console.ReadKey();
       }





我试过的:



我想我没有正确理解其他是如何工作的......否则它会起作用:D请帮忙,我想要学习它的工作方式:(

我希望程序在你写不(或其他任何东西 - 这就是我觉得其他有效)时写下多么可耻,但没有成功程序停止。



What I have tried:

I think I don´t properly understand how does "else" work.. otherwise it would have worked :D Please help, I want to learn the way this works :(
I want the program to write "what a shame" when u Write "no" (or anything else - thats how I feel "else" works), but no success, program just stops.

推荐答案


if (continue1 == "yes")
{
    continue1 = Console.ReadLine();
}
else
{
    Console.WriteLine("What a shame :(");
}





避免歧义。



It avoids ambiguity.


static void Main(string[] args)
       { string continue1 = "yes";
 

 
           while (continue1 == "yes")
 
           {
               Console.WriteLine("your name?:");
               string jmeno = Console.ReadLine();
               Console.WriteLine(jmeno + " is the best!");
 
               Console.WriteLine("New name? (yes/no)");
               continue1 = Console.ReadLine(); //read the user input before checking it with the if statment
               if (continue1 == "yes")
               {
                   //do something hwne the input is yes or in this case repeat the loop
               }
              else Console.WriteLine("What a shame :(");
 
           }
           Console.ReadKey();
       }


这篇关于如果..其他问题,请帮忙的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 22:19