C# 辞書Dictionaryの値を取得するサンプル
環境
Windows 10 Home 64bit
Microsoft Visual Studio Community 2022
構文
Dictionary<int, string> 辞書変数名 = new Dictionary<int, string>();
辞書変数名[キー]=値
辞書のkeyを使用して辞書の値を取得します。
使用例
using System;
namespace ConsoleApp1
{
internal class Program
{
static void Main(string[] args)
{
Dictionary<int, string> dict = new Dictionary<int, string>();
dict[0] = "tokyo";
dict[1] = "oosaka";
dict[2] = "fukuoka";
System.Console.WriteLine(dict[0]);
System.Console.WriteLine(dict[1]);
System.Console.WriteLine(dict[2]);
}
}
}
実行結果
tokyo
oosaka
fukuoka