Back to questions
JuniorTheoryCommon
What does the program print (lines separated by spaces)?
Console.WriteLine(Label(10));
Console.WriteLine(Label(50));
string Label(int n) => n switch
{
> 10 => "big",
> 0 => "positive",
_ => "other",
};positive big
- Expecting a compile error because
50fits two arms: overlapping arms are legal, and only an arm that can never win fails to compile. - Expecting the last matching arm, or
_, to win: the arms are tried from top to bottom, and the first match ends the choice.
- What happens if you swap the arms
> 10and> 0? - Which arm does
Label(-5)reach, and why?