Hi have a question,i know it is always a good practice to include default in the switch,but can it be omitted in this case? As i see it would be redundant.
static void Main(string[] args)
{
bool quit = false;
do
{
var option = ShowMenu();
switch (option)
{
case 1:
CreateStudentData();
break;
case 2:
DisplayStudentData();
break;
case 3:
DisplayDataByIdReversed();
break;
case 4:
quit = true;
Console.WriteLine( "Thanks for using the app.\n" );
break;
}
} while (!quit);
}
public static int ShowMenu()
{
Console.WriteLine("\t\t1 Create student data");
Console.WriteLine("\t\t2 Display student data");
Console.WriteLine("\t\t3 Display student data by reverse ID order");
Console.WriteLine("\t\t4 Exit");
Console.WriteLine("\n");
int option;
while (true)
{
Console.Write("\t\tEnter Option Here: ");
try
{
option = Int32.Parse(Console.ReadLine());
if (option < 1 || option > 4)
{
throw new Exception();
}
}
catch
{
Console.WriteLine("Invalid input,must be choice 1-4");
continue;
}
break;
}
return option;
}