Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
学ぶ チャレンジ:イテレーター | Structs & Enumerators
C#オブジェクト指向構造

bookチャレンジ:イテレーター

メニューを表示するにはスワイプしてください

空欄を埋めて、enum定義を完成させてください。コードを読み、enumの名前と必要なメンバーを特定してください。

index.cs

index.cs

copy
12345678910111213141516171819202122232425262728293031323334353637
using 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; } } }
  1. enum定数へアクセスする際は、enumName.constName構文を使用します。ここでenumNameは列挙体の名前です。
  2. enumには5つの要素が必要です。switch文のcaseを確認し、どの定数が使用されているかを調べてください。そのうちの1つはInvisibilityです。
index.cs

index.cs

copy
12345678910111213141516171819202122232425262728293031323334353637383940
using 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

AIに質問する

expand

AIに質問する

ChatGPT

何でも質問するか、提案された質問の1つを試してチャットを始めてください

セクション 2.  11
some-alt