I have the following code in c# with an enum and I loop through it with a for. I converted the enumeration to byte in the same for to be able to compare it and I have an error when entering the value of the option that I want to see:
The line error is marked
static void Main(string[] args)
{
Console.WriteLine("Menu de opciones: ");
Menu opcion;
for(opcion = 0; (byte)opcion <=2; opcion++)
{
Console.WriteLine("{0}) {1}", opcion.GetHashCode(), opcion.ToString());
}
Console.WriteLine("Ingrese una opcion: ");
//aqui esta el error en el Console.ReadLine
opcion = Covert.ToByte(Console.ReadLine());
switch (opcion)
{
case Menu.Alta:
Console.WriteLine("Ingresar nombre para dar de alta");
break;
case Menu.Baja:
Console.WriteLine("Seleccionar nombre para eliminar");
break;
case Menu.Modificacion:
Console.WriteLine("Seleccionar nombre para modificar");
break;
}
}
You would have to cast the option to the type of the
enum
Something like this
Cast to the type Menu and correct the call to Convert* with "n"