c#流程控制
if
Console.WriteLine("请输入用户名"); string name = Console.ReadLine(); Console.WriteLine("请输入密码"); string passWord = Console.ReadLine(); bool d = (name == "admin" && passWord == "111111"); if (d) { Console.WriteLine("登陆成功哦!"); } Console.ReadKey();
if-else
Console.WriteLine("小马,你的数学考了多少分?"); int score = Convert.ToInt32(Console.ReadLine()); if (score > 90) { Console.WriteLine("奖励你100元哦"); } else { Console.WriteLine("奖励你最爱吃的大嘴巴子哦"); } Console.ReadKey();
if-else if
Console.WriteLine("你是谁阿"); string s = Console.ReadLine().ToString(); if (s == "爷爷") { Console.WriteLine("grandpa"); } else if (s == "爸爸") { Console.WriteLine("dad"); } else if (s == "儿子") { Console.WriteLine("son"); } Console.ReadKey();
switch-case
bool b = true; double salary = 5000; Console.WriteLine("请输入赵鸡的工作评定等级"); string level = Console.ReadLine(); switch (level) { case "a": salary += 500; break; case "b": salary += 300; break; case "c": salary += 100; break; default: Console.WriteLine("程序有误,请重新输入"); b = false; break; } if (b) { Console.WriteLine("赵鸡明年的工资为{0}元", salary); } Console.ReadKey();