Uitdaging: Enumerator
Vul de lege plekken in om de enum-definitie te voltooien. Lees de code en bepaal wat de naam van de enum is, en welke leden deze moet bevatten.
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; } } }
- Bij het benaderen van een enum-constante gebruiken we de syntaxis
enumName.constName
, waarbijenumName
de naam van de enumerator is. - De enum moet vijf elementen bevatten. Kijk in de cases van de switch-instructie om te achterhalen welke constanten worden gebruikt. Eén daarvan is
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; } } }
Was alles duidelijk?
Bedankt voor je feedback!
Sectie 2. Hoofdstuk 11
Vraag AI
Vraag AI
Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.
Awesome!
Completion rate improved to 2.04
Uitdaging: Enumerator
Veeg om het menu te tonen
Vul de lege plekken in om de enum-definitie te voltooien. Lees de code en bepaal wat de naam van de enum is, en welke leden deze moet bevatten.
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; } } }
- Bij het benaderen van een enum-constante gebruiken we de syntaxis
enumName.constName
, waarbijenumName
de naam van de enumerator is. - De enum moet vijf elementen bevatten. Kijk in de cases van de switch-instructie om te achterhalen welke constanten worden gebruikt. Eén daarvan is
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; } } }
Was alles duidelijk?
Bedankt voor je feedback!
Sectie 2. Hoofdstuk 11