I am working my way through the c# learning track and have a query about the switch statements in the football match exercise.
The following snippet of code works in the online editor but when I bring it into Visual Studio 2022, I get an error that the type or namespace ‘Foul’ cannot be found in the AnalyzeOffField method.
Does the online editor automatically create these types in the background when running the tests ?
public static string AnalyzeOnField(int shirtNum)
{
switch (shirtNum)
{
case 1:
return “goalie”;
break;
case 2:
return “left back”;
break;
case 3:
case 4:
return “center back”;
break;
case 5:
return “right back”;
break;
case 6:
case 7:
case 8:
return “midfielder”;
break;
case 9:
return “left wing”;
break;
case 10:
return “striker”;
case 11:
return “right wing”;
break;
default:
throw new ArgumentOutOfRangeException(nameof(shirtNum));
}
}
public static string AnalyzeOffField(object report)
{
switch (report)
{
case Foul foul:
return "The referee deemed a foul.";
case int supporters:
return $"There are {supporters} supporters at the match.";
case string announcement:
return announcement;
default: throw new ArgumentOutOfRangeException();
}
}