I have the following error in c#: I create the variable "year" and I want to compare with another variable ("check400") inside a switch. I had no problems with this same code in visual basic. But in C# yes, and I don't understand what the error means. Please let me know if you see it, thank you very much.
**class NumeroDiasDelMes
{
enum Meses : int
{
Enero = 1,
Febrero = 2,
Marzo = 3,
Abril = 4,
Mayo = 5,
junio = 6,
Julio = 7,
Agost = 8,
Septiembre = 9,
Octubre = 10,
Noviembre = 11,
Diciembre = 12
}
static void Main(string[] args)
{
int ano, resultado4, verificar4, resultado100, verificar100, resultado400, verificar400;
int bisiesto = 2;
Console.WriteLine("ingrese el Año");
ano = Convert.ToInt32(Console.ReadLine());
resultado4 = ano / 4;
verificar4 = resultado4 * 4;
Console.WriteLine(verificar4);
resultado100 = ano / 100;
verificar100 = resultado100 * 100;
Console.WriteLine(verificar100);
resultado400 = ano / 400;
verificar400 = resultado400 * 400;
Console.WriteLine(verificar400);
switch (verificar400)
{
case ano :
//aqui en case ano linea de error
Console.WriteLine("Es bisiesto");
bisiesto = 1;
break;
}**
It is not possible, unless tu
ano
is constant and not variable.It is something already officially defined by Microsoft: https://docs.microsoft.com/en-us/dotnet/csharp/misc/cs0150
The switch cases must be constant values: