Created
September 29, 2021 15:05
-
-
Save aevitas/e45444164e4a4802f0f26dbd53cbeb95 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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