title: Add to array list from another array list
body: <p>I have a program where I am trying to move items from one arraylist to another via a listbox but when I try to add it to the the second arraylist it does not add there.</p>
  
  <pre><code>ArrayList list1 = new ArrayList();
  ArrayList list2 = new ArrayList();
  list1.Add(new Class(var1, var2, var3, var4, var5, var6, var7));
  foreach (object o in list1)
          {
              class m = (class)o;
              selectionBox.Items.Add(m);
          }
  </code></pre>
  
  <p>I initialised everything above and added everything to the class and then to the listbox. Note the vars I have got from an XML file.</p>
  
  <pre><code> bool req = true;
  
          if (selectionBox.SelectedItem != null)
          {
              Count++;
              errorLabel.Text = "";
  
              for (int i = 0; i &lt; selectionBox.Items.Count; i++)
              {
                  if (selectionBox.GetSelected(i) == true)
                  {
  
                      class m = selectionBox.SelectedItem as class;
                      if (m.var2 == ((Modules)selectionBox.Items[i]).var2)
                      {
                          list2.Add(list1.IndexOf(i));
                      }
                  }
              }
  
          }
          else
          {
              errorLabel.Text = "Error";
          }
  </code></pre>
  
  <p>Here I am trying to add it to the second array list but it does not work the if statement however is correct I have tried this with print statements. So can someone tell me why the following line does not add to the list?</p>
  
  <pre><code> list2.Add(list1.IndexOf(i));
  </code></pre>