C#语法基础05_switch
switch(expression){
case constant-expression :
statement(s);
break;
case constant-expression :
statement(s);
break;
/* 您可以有任意数量的 case 语句 */
default : /* 可选的 */
statement(s);
break;
}
例子,通过switch实现的温度转化方式的选择:
class Program {
static void Main(string[] args) {
int choice = '0';
bool loopFlag = true;
bool firstLoop = true;
PrintMsg();
choice = GetChoice();
while (loopFlag) {
if (firstLoop) {
firstLoop = false;
} else {
Console.WriteLine("Choose the conversion mode again\n");
choice = GetChoice();
}
switch (choice) {