title: List set index c#
body: <p>I am using a <strong>List</strong> construct to handle the sequence in which images are drawn in "OnPaint". Now if my images are re-ordered (e.g. "brought to front" or "..to back"), I'd need to reposition them in my List.
  I have trouble doing so, because List doesn't support a method similar to <strong>setIndex()</strong>.</p>
  
  <p>So what I am trying to do is basically:</p>
  
  <pre><code>    private List&lt;BitmapWithProps&gt; activeImages = new List&lt;BitmapWithProps&gt;();
  
      public void addActiveImage(BitmapWithProps image)
      {
          activeImages.Add(image);
      }
  
      public BitmapWithProps getActiveImage(int index)
      {
          return activeImages[index];
      }
  
      public void removeActiveImage(int index)
      {
          activeImages.RemoveAt(index);
      }
  
      public void removeActiveImage(BitmapWithProps item)
      {
          activeImages.Remove(item);
      }
  
      public void swapActiveImageIndex(int sourceIndex, int destIndex)
      {
          // what would the code look like in here if I were to swap
          // the 2nd item (1) with the 4th one (3) in a 5-item-List (0 - 4)
      }
  </code></pre>
  
  <p>I want to be able to swap an index.. sort of. I could "insert" a new item into the List at the index it should go to and assign the value and then delete the other "source". However it doesn't seem elegant in any way.</p>
  
  <p>I'd be glad for any hints and please excuse me if I overlooked a thread - I did search though, before asking.</p>
  
  <p>dS.</p>