Skip to content

Instantly share code, notes, and snippets.

@aevitas
Created September 29, 2021 15:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aevitas/e45444164e4a4802f0f26dbd53cbeb95 to your computer and use it in GitHub Desktop.
Save aevitas/e45444164e4a4802f0f26dbd53cbeb95 to your computer and use it in GitHub Desktop.
namespace CSharpByExample
{
public class Program
{
public static void Main(string[] args)
{
string utensil = Console.ReadLine();
// Default switch statement
switch (utensil)
{
case "knife":
Console.WriteLine("Placed to the right of the plate");
break;
case "spoon":
Console.WriteLine("Placed above the plate");
break;
case "fork":
Console.WriteLine("Placed to the left of the plate");
break;
default:
Console.WriteLine("This does not belong on the table");
break;
}
// Switch expression
void PrintUtensilPlacement(string item)
{
string placement = item switch
{
"knife" => "Placed to the right of the plate",
"spoon" => "Placed above the plate",
"fork" => "Placed to the left of the plate",
_ => "This does not belong on the table"
};
Console.WriteLine(placement);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment