我是C#的新手,我刚刚来自PHP。C#if/else线程中断
具体而言,让我“复制/粘贴”一段难以理解的代码。
我有一个函数,它从“当前年份”中减去“出生年份”并返回更新年龄的年份。现在,我需要检查用户的年龄是否低于30岁。打印出“你太年轻了,无法查看此页面”信息,然后询问他/她是否想继续回答其余的问题。然后我们根据答案做出决定。如果回答“是”,我们,如下所示,继续。现在我想知道,但如果用户说“不”,会怎么样?如何中断代码?
例如在PHP中,我用这个键入 - “exit()”。
在此先感谢。
if (ma.HowOldImI(date1, date2) < 30)
{
Console.WriteLine("you are too young to view this page");
Console.WriteLine("would you like to continue the session?");
string confirm = Console.ReadLine();
if (confirm == "yes")
{
Console.WriteLine("Please type your name");
string nm = Console.ReadLine();
Console.WriteLine("Please type your born year");
int ag = Convert.ToInt16(Console.ReadLine());
gr.YouWereBorn(nm, ag);
}
}
else
{
Console.WriteLine("You are " + ma.HowOldImI(date1, date2) + " years old\n");
}
要退出方法,您需要“返回” – seekerOfKnowledge 2012-08-06 13:51:42
“如何中断代码”是什么意思?这是控制台应用程序的主要功能吗?在从main调用的过程中?当代码被“中断”时,你想要做什么? – JTMon 2012-08-06 13:54:30
最终的应用程序是否也将成为控制台应用程序? – 2012-08-06 13:54:30