Завдання: Перелічувач
Заповніть пропуски, щоб завершити визначення перерахування (enum). Прочитайте код і визначте, як називається enum, а також які члени він повинен містити.
index.cs
12345678910111213141516171819202122232425262728293031323334353637using System; class Program { // Fill in the blanks below this line ___ ___ { ___ } static void Main(string[] args) { Potion potion = Potion.Invisibility; switch (potion) { case Potion.Invisibility: Console.WriteLine("You drink the Invisibility potion and vanish from sight!"); break; case Potion.Strength: Console.WriteLine("You drink the Strength potion and feel a surge of power!"); break; case Potion.Healing: Console.WriteLine("You drink the Healing potion and your wounds magically mend."); break; case Potion.FireResistance: Console.WriteLine("You drink the Fire Resistance potion and become impervious to flames."); break; case Potion.Teleportation: Console.WriteLine("You drink the Teleportation potion and find yourself in a new location!"); break; default: Console.WriteLine("Invalid potion type!"); break; } } }
- Для доступу до константи enum використовується синтаксис
enumName.constName
, деenumName
— це назва перерахування. - Enum повинен містити п’ять елементів. Перегляньте випадки оператора switch, щоб визначити, до яких констант здійснюється доступ. Одна з них —
Invisibility
.
index.cs
12345678910111213141516171819202122232425262728293031323334353637383940using System; class Program { enum Potion { Invisibility, Strength, Healing, FireResistance, Teleportation } static void Main(string[] args) { Potion potion = Potion.Invisibility; switch (potion) { case Potion.Invisibility: Console.WriteLine("You drink the Invisibility potion and vanish from sight!"); break; case Potion.Strength: Console.WriteLine("You drink the Strength potion and feel a surge of power!"); break; case Potion.Healing: Console.WriteLine("You drink the Healing potion and your wounds magically mend."); break; case Potion.FireResistance: Console.WriteLine("You drink the Fire Resistance potion and become impervious to flames."); break; case Potion.Teleportation: Console.WriteLine("You drink the Teleportation potion and find yourself in a new location!"); break; default: Console.WriteLine("Invalid potion type!"); break; } } }
Все було зрозуміло?
Дякуємо за ваш відгук!
Секція 2. Розділ 11
Запитати АІ
Запитати АІ
Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат
Suggested prompts:
What is the code for the switch statement so I can see all the enum members?
Can you show me the part of the code where the enum is defined?
Can you list all the constants used in the switch statement?
Awesome!
Completion rate improved to 2.04
Завдання: Перелічувач
Свайпніть щоб показати меню
Заповніть пропуски, щоб завершити визначення перерахування (enum). Прочитайте код і визначте, як називається enum, а також які члени він повинен містити.
index.cs
12345678910111213141516171819202122232425262728293031323334353637using System; class Program { // Fill in the blanks below this line ___ ___ { ___ } static void Main(string[] args) { Potion potion = Potion.Invisibility; switch (potion) { case Potion.Invisibility: Console.WriteLine("You drink the Invisibility potion and vanish from sight!"); break; case Potion.Strength: Console.WriteLine("You drink the Strength potion and feel a surge of power!"); break; case Potion.Healing: Console.WriteLine("You drink the Healing potion and your wounds magically mend."); break; case Potion.FireResistance: Console.WriteLine("You drink the Fire Resistance potion and become impervious to flames."); break; case Potion.Teleportation: Console.WriteLine("You drink the Teleportation potion and find yourself in a new location!"); break; default: Console.WriteLine("Invalid potion type!"); break; } } }
- Для доступу до константи enum використовується синтаксис
enumName.constName
, деenumName
— це назва перерахування. - Enum повинен містити п’ять елементів. Перегляньте випадки оператора switch, щоб визначити, до яких констант здійснюється доступ. Одна з них —
Invisibility
.
index.cs
12345678910111213141516171819202122232425262728293031323334353637383940using System; class Program { enum Potion { Invisibility, Strength, Healing, FireResistance, Teleportation } static void Main(string[] args) { Potion potion = Potion.Invisibility; switch (potion) { case Potion.Invisibility: Console.WriteLine("You drink the Invisibility potion and vanish from sight!"); break; case Potion.Strength: Console.WriteLine("You drink the Strength potion and feel a surge of power!"); break; case Potion.Healing: Console.WriteLine("You drink the Healing potion and your wounds magically mend."); break; case Potion.FireResistance: Console.WriteLine("You drink the Fire Resistance potion and become impervious to flames."); break; case Potion.Teleportation: Console.WriteLine("You drink the Teleportation potion and find yourself in a new location!"); break; default: Console.WriteLine("Invalid potion type!"); break; } } }
Все було зрозуміло?
Дякуємо за ваш відгук!
Секція 2. Розділ 11