42.(c#) switch..case用法

2021/7/23 22:19:03

本文主要是介绍42.(c#) switch..case用法,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

using System;
class ChooseSubject
{
 static void Main()
 {
  int i;
  string str;
  Console.WriteLine ("Please choose your favorite subjects:-1 is quit.");
  Console.WriteLine ("1.Chinese.");
  Console.WriteLine ("2.Maths.");
  Console.WriteLine ("3.English.");
  Console.WriteLine ("4.Physical.");
  Console.WriteLine ("-1 is quit.");
  do
  {
   str=Console.ReadLine ();
   i=Int32.Parse (str);
   switch(i)
   {
    case 1:
     Console.WriteLine ("You like chinese very much.");
     break;
    case 2:
     Console.WriteLine ("You like maths very much.");
     break;
    case 3:
     Console.WriteLine ("You like english very much.");
     break;
    case 4:
     Console.WriteLine ("You like physical very much.");
     break;
    case -1:
     break;
    default:
     Console.WriteLine ("I'm sorry.You can't choose this subject.");
     break;
   }
 
  }while(i!=-1);
  Console.WriteLine ("Byebye!");
 }
}



这篇关于42.(c#) switch..case用法的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程