F
fred
I tested following program gives runtime error:
Unhandled Exception: System.InvalidProgramException:
Common Language Runtime detected an invalid program.
using System;
public class SwitchTest
{
static void Main()
{
const int i = 1;
switch (i)
{
case 0:
Console.WriteLine
(0);
goto default;
case 1:
Console.WriteLine
(1);
goto case 0;
default:
Console.WriteLine
("all others");
break;
}
}
}
However, by rearranging the case section, this bug is
avoided:
public class SwitchTest
{
static void Main()
{
const int i = 1;
switch (i)
{
case 1:
Console.WriteLine
(1);
goto case 0;
case 0:
Console.WriteLine
(0);
goto default;
default:
Console.WriteLine
("all others");
break;
}
}
}
According to documentation, since C# has a "no fall
through" rule to ensure the order of case doesn't matter,
I think this is a bug.
Unhandled Exception: System.InvalidProgramException:
Common Language Runtime detected an invalid program.
using System;
public class SwitchTest
{
static void Main()
{
const int i = 1;
switch (i)
{
case 0:
Console.WriteLine
(0);
goto default;
case 1:
Console.WriteLine
(1);
goto case 0;
default:
Console.WriteLine
("all others");
break;
}
}
}
However, by rearranging the case section, this bug is
avoided:
public class SwitchTest
{
static void Main()
{
const int i = 1;
switch (i)
{
case 1:
Console.WriteLine
(1);
goto case 0;
case 0:
Console.WriteLine
(0);
goto default;
default:
Console.WriteLine
("all others");
break;
}
}
}
According to documentation, since C# has a "no fall
through" rule to ensure the order of case doesn't matter,
I think this is a bug.