使用switch语句

发布于 2012-11-26  34 次阅读


static void Main(string[] args)
{
const string myName = "karli";
const string sexyName = "angelina";
const string sillyName = "ploppy";
string name;
Console.WriteLine("What is your name?");
name = Console.ReadLine();
switch (name .ToLower() ) //把输入的姓名转换成小写。
{
case myName :
Console .WriteLine ("You have the same name as me!");
break ;
case sexyName :
Console .WriteLine ("My, what aa sexy name you have!");
break ;
case sillyName :
Console.WriteLine("That's a very silly name.");
break;
}
Console.WriteLine("Hello {0}!",name );
Console.ReadKey();

除非注明,本博客所有内容 由 秒速340 创作,采用 知识共享 署名-非商业性使用-禁止演绎 3.0 未本地化版本 许可协议进行许可。