/
aprogrammer
/
dotnet-docs
Обзор
Документация
Войти
/
aprogrammer
/
dotnet-docs
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
docs/csharp/language-reference/statements/snippets/jump-statements/GotoInSwitchExample.cs
38 строк
921 B
Nick Schonning
fix: various typos outside samples/ (#32862)
05 дек 2022, 19:37
Не верифицирован
05 дек 2022, 19:37
d1c3f9f
Код
Авторство
О чём код?
using System; public enum CoffeeChoice { Plain, WithMilk, WithIceCream, } public class GotoInSwitchExample { public static void Main() { Console.WriteLine(CalculatePrice(CoffeeChoice.Plain)); // output: 10.0 Console.WriteLine(CalculatePrice(CoffeeChoice.WithMilk)); // output: 15.0 Console.WriteLine(CalculatePrice(CoffeeChoice.WithIceCream)); // output: 17.0 } private static decimal CalculatePrice(CoffeeChoice choice) { decimal price = 0; switch (choice) { case CoffeeChoice.Plain: price += 10.0m; break; case CoffeeChoice.WithMilk: price += 5.0m; goto case CoffeeChoice.Plain; case CoffeeChoice.WithIceCream: price += 7.0m; goto case CoffeeChoice.Plain; } return price; } }