Created
June 20, 2015 16:11
-
-
Save zerosalife/e3882aa5ffd5dd614c9a to your computer and use it in GitHub Desktop.
Create a Dictionary of Lists in Unity C#
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
using UnityEngine; | |
using System.Collections.Generic; | |
public class MakeDictionaryOfLists : MonoBehaviour { | |
Dictionary<string, List<int>> table = new Dictionary<string, List<int>>(); | |
void Start() { | |
// Fill our table with Lists containing ints using Arrays to intialize | |
// the Lists. | |
table["a"] = new List<int>(){1}; | |
table["b"] = new List<int>(){2}; | |
table["c"] = new List<int>(){3}; | |
foreach(string str in table.Keys) { | |
// Get the value for our Key. | |
List<int> value = table[str]; | |
// If the Key is the desired Key, append to its list. | |
if(str == "c") { | |
value.Add(4); | |
} | |
// print the first item in each of the Lists. | |
Debug.Log(value[0]); | |
} | |
// Print the appended item to see that it worked. | |
Debug.Log(table["c"][1]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment