-
-
Save todorok1/13d19ca62d99cab15602605111647291 to your computer and use it in GitHub Desktop.
C#のDictionaryでforeach文を回す
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// アイテムIDとアイテム名の辞書を作成します。 | |
Dictionary<int, string> itemDict = new Dictionary<int, string>(); | |
// Addメソッドで値を追加します。 | |
itemDict.Add(1, "ポーション"); | |
itemDict.Add(2, "ハイポーション"); | |
itemDict.Add(3, "エーテル"); | |
// KeyValuePairでキーと値のセットを作ります。 | |
foreach (KeyValuePair<int, string> pair in itemDict) | |
{ | |
int itemId = pair.Key; | |
string itemName = pair.Value; | |
Debug.Log(itemId + ": " + itemName); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment