public static void UsingTernaryConditionalOperator() { fishType fish = fishType.Trout; var result = (fish == fishType.Trout) ? $"This fish is a {fishType.Trout}" : $"This fish is not a {fishType.Trout}"; Console.WriteLine(result); }
public static void UsingSwitchCase() { fishType fish = fishType.Trout; switch (fish) { case fishType.Catfish: { Console.WriteLine($"This fish is a {fishType.Catfish}."); break; } case fishType.Goldfish: Console.WriteLine($"This fish is a {fishType.Goldfish}."); break; case fishType.Trout: Console.WriteLine($"This fish is a {fishType.Trout}."); break; case fishType.Lobster: case fishType.Eel: Console.WriteLine("This is not a real fish."); break; default: Console.WriteLine("Why is there no fish?"); break; } }
public static void UsingIfElse() { fishType fish = fishType.Trout; if (fish == fishType.Goldfish) { Console.WriteLine($"This fish is a {fishType.Goldfish}"); } else if (fish == fishType.Catfish) { Console.WriteLine($"This fish is a {fishType.Catfish}"); } else if (fish == fishType.Trout) { Console.WriteLine($"This fish is a {fishType.Trout}"); } else { Console.WriteLine("Why is there no fish?"); } }
public static void SwitchFish(fishType typeOfFish) { }