C#switch语句简单测试
生活随笔
收集整理的這篇文章主要介紹了
C#switch语句简单测试
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
switch的簡單測試。。。。。
代碼:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;namespace switch語句 {class Program{static void Main(string[] args){//輸入要選擇的城市序號string condition=Console.ReadLine(); //輸入選擇的序號string city;switch (condition) //( )里可以是字符串,也可以是整數,只是要和case后面的類型對應{case "1": //case語句后面必須以break結束,否則就不完整city ="長沙"; break;case "2":city = "北京";break;case "3":city = "廣州";break;default:city = null;break;}Console.WriteLine(city); //輸出選擇的結果Console.ReadKey();}} }測試結果:
總結
以上是生活随笔為你收集整理的C#switch语句简单测试的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: HashTable哈希表的用法---简单
- 下一篇: 学习C#从哪些方面去学习,才能全面掌握基