Created
November 6, 2015 20:47
-
-
Save Marneus68/0d3b4ad86414dce9fb21 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 ClosureTest : MonoBehaviour { | |
public delegate void TestAction(); | |
void Start () { | |
Dictionary<string, List<string>> dict = new Dictionary<string, List<string>>() { | |
{ "Foo" , new List<string>() { "Goo", "Hoo", "Ioo" } }, | |
{ "Bar" , new List<string>() { "Car", "Dar", "Ear" } } | |
}; | |
Dictionary<string, TestAction> acts = new Dictionary<string, TestAction>(); | |
foreach (var l in dict) { | |
// Adding action with the help of a lambda expression | |
acts.Add(l.Key, () => { | |
foreach (var s in l.Value) { | |
Debug.Log("Submenu : " + s ); | |
} | |
}); | |
} | |
foreach (var l in acts) { | |
Debug.Log("Menu name : " + l.Key); | |
l.Value(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment