演習課題「Dictionary作成しよう」
Dictinoaryを作成し、
キーが「ザコ」 / バリューが「スライム」
キーが「中ボス」 / バリューが「ドラゴン」
キーが「ラスボス」 / バリューが「魔王」
というデータを追加してください。
期待する出力値
スライム
ドラゴン
魔王
演習課題「キーを変数にして値を取り出そう」
右側のコードエリアには、あらかじめDictionaryが定義されています。
変数でキーを指定し、スライムを呼び出してください。
期待する出力値
スライム
#02:Dictionaryを作ろう
Dictionaryの基本操作について学習します。そして、Dictionaryの作成・表示といった機能を試します。
// Dictionaryを作ろう
using System;
using System.Collections.Generic;
class Lesson09
{
    public static void Main()
    {
        string[] enemyArray = { "スライム", "モンスター", "ドラゴン" };
        Console.WriteLine(enemyArray[0]);
        Console.WriteLine(enemyArray[1]);
        Console.WriteLine(enemyArray[2]);
        Console.WriteLine();
        var enemyDictionary = new Dictionary<String, String>();
        enemyDictionary.Add("ザコ", "スライム");
        enemyDictionary.Add("中ボス", "ドラゴン");
        enemyDictionary.Add("ラスボス", "魔王");
        Console.WriteLine(enemyDictionary["ザコ"]);
        Console.WriteLine(enemyDictionary["中ボス"]);
        Console.WriteLine(enemyDictionary["ラスボス"]);
        Console.WriteLine();
        var level = "ラスボス";
        Console.WriteLine(enemyDictionary[level]);
    }
}
C# Dictionaryのサンプル | ITSakura
https://itsakura.com/csharp-dictionary
C# の Dictionary
https://takachan.hatenablog.com/entry/2015/06/23/160515
Dictionary
https://docs.microsoft.com/ja-jp/dotnet/api/system.collections.generic.dictionary-2?view=netframework-4.8