title: List of delegates and invoking
body: <p>I am creating a smaller RPG game in ASP.NET. In this game I have an items architecture, where each item has some methods. For instance, all items should share a method like "<strong>Drop</strong>", "<strong>Examine</strong>" and "<strong>Use</strong>". Some items will have to be extended with methods like "<strong>Operate</strong>", "<strong>Calculate</strong>" and such.</p>
  
  <p>So far, I have created the following object GameActionList:</p>
  
  <pre><code>public delegate void MyDelegate();
  
  public class GameActionList
  {
      public List&lt;MyDelegate&gt; Items = new List&lt;MyDelegate&gt;();
  
      public void Add(MyDelegate del)
      {
          Items.Add(del);
      }
  
      public void CallDelegates()
      {
          foreach (MyDelegate myDelegate in Items)
          {
              myDelegate();
          }
      }
  }
  </code></pre>
  
  <p>I have a BaseItem class, which has this GameActionList. The get property of this in the BaseItem class is like this:</p>
  
  <pre><code>    public GameActionList Actions 
      { 
          get
          {
              GameActionList actions = new GameActionList();
              actions.Add(this.Drop);
              actions.Add(this.Examine);
              return actions;
          }
      }
  </code></pre>
  
  <p>This is fine, BUT... I have some problems!</p>
  
  <p><strong>My problem</strong></p>
  
  <p>I need a way more generic GameActionList. I need to have a list of not only voids, but also functions.. Also, I need both methods with parameters and without parameters.</p>
  
  <p>For instance: The <strong>Drop</strong> method will need a Player object, so he can Drop the item. The <strong>Examine</strong> method will need to return a string descriping the item.</p>
  
  <p>Also, I need some data which I don't know when I Initialize the GameActionList: I first know these data when I invoke the method...</p>
  
  <p>So I have two questions:</p>
  
  <ol>
  <li>How do you extend the GameActionList, so it can contain a list of both voids and functions andalso these both can have parameters or not.. (AND DOES IT EVEN MAKE SENSE??)</li>
  <li>How can I give some data to the method later in the cycle, like when invoking?</li>
  </ol>
  
  <p><em>Also... This might be a very stupid way to do it, so if you have some way more elegant solution.. I'm more than ready to hear it</em>!</p>
  
  <p>Thanks a lot...!
  Lars</p>