Head, meet desk
-
What idiot wrote
goto case default
instead ofgoto default
in one of my C#switch
statements, causing an infinite loop? :doh: It certainly couldn't have been me. :-O For future reference: given:enum Foo { One, Two }
then:
switch (foo)
{
case Foo.One: goto default;
default: Console.WriteLine("Default");
}compiles to:
if (foo != 0) { }
Console.WriteLine("Default");whereas:
switch (foo)
{
case Foo.One: goto case default;
default: Console.WriteLine("Default");
}compiles to:
if (foo == Foo.One)
{
while (true)
{
}
}
Console.WriteLine("Default");
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
What idiot wrote
goto case default
instead ofgoto default
in one of my C#switch
statements, causing an infinite loop? :doh: It certainly couldn't have been me. :-O For future reference: given:enum Foo { One, Two }
then:
switch (foo)
{
case Foo.One: goto default;
default: Console.WriteLine("Default");
}compiles to:
if (foo != 0) { }
Console.WriteLine("Default");whereas:
switch (foo)
{
case Foo.One: goto case default;
default: Console.WriteLine("Default");
}compiles to:
if (foo == Foo.One)
{
while (true)
{
}
}
Console.WriteLine("Default");
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
What idiot wrote
goto case default
instead ofgoto default
in one of my C#switch
statements, causing an infinite loop? :doh: It certainly couldn't have been me. :-O For future reference: given:enum Foo { One, Two }
then:
switch (foo)
{
case Foo.One: goto default;
default: Console.WriteLine("Default");
}compiles to:
if (foo != 0) { }
Console.WriteLine("Default");whereas:
switch (foo)
{
case Foo.One: goto case default;
default: Console.WriteLine("Default");
}compiles to:
if (foo == Foo.One)
{
while (true)
{
}
}
Console.WriteLine("Default");
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer