格式: switch (表达式) { case 常量表达式:条件语句; case 常量表达式: 条件语句; case 常量表达式: 条件语句; case 常量表达式: 条件语句; case 常量表达式: 条件语句; default: break; } using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace _5_2_分支语句之switch语句 { class Program { static void Main(string[] args) { Console.WriteLine("输入1-7的一个数字"); int week = int.Parse(Console.ReadLine()); switch (week) { case 1: Console.WriteLine("星期一"); break; case 2: Console.WriteLine("星期二"); break; case 3: Console.WriteLine("星期三"); break; case 4: Console.WriteLine("星期四"); break; case 5: Console.WriteLine("星期五"); break; case 6: Console.WriteLine("星期六"); break; case 7: Console.WriteLine("星期日"); break; default:Console.WriteLine("输入有误"); break; } } } } |
|
来自: 工厂应用 > 《51自学网C#学习笔记》