CSharp examples for Language Basics:switch
switch statements let you branch program execution based on a selection of possible values.
using System;/*w w w.j av a2s. c o m*/ class Test { static void ShowCard(int cardNumber) { switch (cardNumber) { case 13: Console.WriteLine ("King"); break; case 12: Console.WriteLine ("Queen"); break; case 11: Console.WriteLine ("Jack"); break; case -1: // Joker is -1 goto case 12; // In this game joker counts as queen default: // Executes for any other cardNumber Console.WriteLine (cardNumber); break; } } static void Main(){ ShowCard(13); } }