In this example, i’ll show you How to Print day of week name using switch-case in C# Console App.
C# Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
static void Main(string[] args) { int weeknumber; //Reading week no from user Console.WriteLine("Enter week number(1-7): "); weeknumber = Convert.ToInt32(Console.ReadLine()); switch (weeknumber) { case 1: Console.WriteLine("Monday"); break; case 2: Console.WriteLine("Tuesday"); break; case 3: Console.WriteLine("Wednesday"); break; case 4: Console.WriteLine("Thursday"); break; case 5: Console.WriteLine("Friday"); break; case 6: Console.WriteLine("Saturday"); break; case 7: Console.WriteLine("Sunday"); break; default: Console.WriteLine("Invalid input! Please enter week no. between 1-7."); break; } Console.ReadLine(); } |
Output: