Create a Console application to test usage of Switch case construct. Accept some integer from user as command line argument and using a switch case construct, check if the value entered is 1, 2, 3, 4 or 5. Print some message in each case. If the value is other than the above values, then print error message.
using System;
namespace SwitchCaseDemo
{
class Program
{
static void Main(string[] args)
{
Console.Write("Input some integer: ");
var input = Console.ReadLine();
if (int.TryParse(input, out var number))
{
switch (number)
{
case 1:
Console.WriteLine("You entered ONE");
break;
case 2:
Console.WriteLine("You entered TWO");
break;
case 3:
Console.WriteLine("You entered THREE");
break;
case 4:
Console.WriteLine("You entered FOUR");
break;
case 5:
Console.WriteLine("You entered FIVE");
break;
default:
Console.WriteLine("ERROR: The number entered was not expected!");
break;
}
}
else
Console.WriteLine("ERROR: The value entered is not an integer number!");
}
}
}
Comments
Leave a comment