How do I add a function to a collection?
<p>I have a class that manages keyboard input and fires off <em>KeyPressed</em>, <em>KeyReleased</em>, or <em>KeyHeld</em> events. It only fires off an event if the key exists in the KeyBindings collection of my Controller component. Now that I've got all of that working I'm stuck on a problem. What I want is the following:</p>

<pre><code>Key pressed.

if(Key bind exists)
    Fire key pressed event.

foreach(function in keyBinds)
{
    execute function, fire event, whatever...
}
</code></pre>

<p>I just can't figure out how the foreach loop would work. Any ideas on how I could pull something like this off?</p>

<hr>

<p><strong>KeyboardController Component:</strong></p>

<pre><code>public class KeyboardController : IComponent
{
    //Fields
    private Dictionary&lt;Keys, HashSet&lt;Delegate&gt;&gt; m_keyBindings = new Dictionary&lt;Keys,HashSet&lt;Delegate&gt;&gt;();

    //Properties
    public Dictionary&lt;Keys, HashSet&lt;Delegate&gt;&gt; KeyBindings
    {
        get { return m_keyBindings; }
    }
}
</code></pre>

<p>This is the class that will contain the Keys and their function/delegate/event/whatever bindings. The code for events CANNOT be contained within this class because the class is meant only to store data. I need to pass a Key bind and an action or set of actions to perform when this bind is pressed.</p>

<p><strong>Adding a bind:</strong></p>

<pre><code>//Set key bindings
KeyboardController kbController = entityManager.GetComponent&lt;KeyboardController&gt;(1);
kbController.KeyBindings.Add(Keys.Up, new HashSet&lt;Delegate&gt;());
kbController.KeyBindings[Keys.Up].Add(function);
</code></pre>

<p>I don't know how to make the third line in "Adding a bind:" work.</p>
