Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The problem is with your use of <a href="http://msdn.microsoft.com/en-us/library/system.collections.arraylist.getrange.aspx" rel="nofollow"><code>GetRange</code></a>:</p> <blockquote> <p>This method does not create copies of the elements. The new ArrayList is only a view window into the source ArrayList. However, all subsequent changes to the source ArrayList must be done through this view window ArrayList. If changes are made directly to the source ArrayList, the view window ArrayList is invalidated and any operations on it will return an InvalidOperationException.</p> </blockquote> <p>You're creating two views onto the original <code>ArrayList</code> and trying to work with both of them - but when one view modifies the underlying list, the other view is effectively invalidated.</p> <p>If you change the code to create <em>copies</em> of the sublists - or if you work directly with the original list within specified bounds - then I believe it'll work fine.</p> <p>(As noted in comments, I'd also <em>strongly</em> recommend that you use generic collections.)</p> <p>Here's a short but complete program which demonstrates the problem you're running into:</p> <pre><code>using System; using System.Collections; class Program { static void Main() { ArrayList list = new ArrayList(); list.Add("a"); list.Add("b"); ArrayList view1 = list.GetRange(0, 1); ArrayList view2 = list.GetRange(1, 1); view1[0] = "c"; Console.WriteLine(view2[0]); // Throws an exception } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload