While trying to learn C# Im trying to play with Enum and switch statement. how can I pass the user input into a variable in order to let him select one of the options in an enum?
what is the right way to pass the user input?
my code looks like this:
using System;
namespace switchDemo
{
class Program
{
enum Movies
{
LOTR,
Starwars,
Matirx
}
static void Main(string[] args)
{
Console.WriteLine("Choose the best movie (LOTR, Starwars, Matirx): ");
Movies bestMovie = Convert.ToString(Console.ReadLine());
//Movies bestMovie = Movies.LOTR;
switch (bestMovie)
{
case Movies.LOTR:
Console.WriteLine("thats correct - LOTR");
break;
case Movies.Matirx:
Console.WriteLine("Martix is not the best");
break;
case Movies.Starwars:
Console.WriteLine("StarWars is 2nd best");
break;
default:
Console.WriteLine("choose an option");
break;
}
Console.WriteLine("Hello World!");
}
}
}