if else:用于两种情况的判断。
if esle if :用于处理多条件的区间性判断,else永远跟离它最近的那个if配对。
Console.WriteLine("请输入学员的考试成绩"); int score = Convert.ToInt32(Console.ReadLine()); if (score >= 90) { Console.WriteLine("A"); } else if (score >= 80) { Console.WriteLine("B"); } else if (score >= 70) { Console.WriteLine("C"); } else if (score >= 60) { Console.WriteLine("D"); } else { Console.WriteLine("E"); }
switch case:用来处理多条件定值的判断。
bool b = true; double salary = 5000; Console.WriteLine("请输入年终判定"); string level = Console.ReadLine(); switch (level) { case "A": salary += 500; break; case "B": salary += 200; break; case "C": break; case "D": salary -= 200; break; case "E": salary -= 500; break; default: Console.WriteLine("输入有误,程序退出"); b = false; break; } if (b) { Console.WriteLine("年终{0}", salary); Console.ReadKey(); }
标签:salary,case,判断,Console,else,break,三种,WriteLine,方法 From: https://www.cnblogs.com/chungeblog/p/17221217.html