title: How to handle menu items in C# for passing values
body: <p>I am working in Windows Forms in C#. I have a method where I am adding <code>MenuItem</code>s to the <code>ContextMenu</code> and I implemented the event handlers for the <code>MenuItem</code>s as below:</p>
  <pre><code>public void Form1_Load()
  {
      int index = 0;
      ArrayList ar = new ArrayList();
      ContextMenu cm = new ContextMenu();
      cm.Name = &quot;Test&quot;;
      MenuItem mi = new MenuItem(&quot;All&quot;);
      mi.Click += new EventHandler(mi_All);
  }
  
  private void mi_All(object sender, EventArgs e)
  {
      // Here I want to access the arraylist and integer specified in above method
  }
  </code></pre>
  <p>How can this be done? One possible solution is to declare the <code>ArrayList</code> and <code>int</code> as global variables, but I have a lot of variables like this. If I take this approach, the variables will live until the form gets disposed. So this doesn't work. Is there another way of achieving this?</p>