title: Swapping Objects in an Array - C#
body: <p>In C#, I have an Array of MenuItem. I'm trying to swap the two Objects in index 2 and index 3 of the array without success using the code below:</p>
  
  <pre><code>MenuItem Temp = Items[2];  
  Items[2] = Items[3];  
  Items[3] = Temp;  
  </code></pre>
  
  <p>There must be a reason why the second and third lines aren't working in C# which I may not understand yet. Is anyone able to clarify it a bit more? Do I have to go deeper and swap each property in the objects individually?</p>
  
  <p>Edited - Sorry. Looks like I made a mess of the code when trying to clean it up for posting. Corrected now.</p>
  
  <p>The actual code is :</p>
  
  <pre><code>MenuItem TempButton = MenuItems.Items[SelectedButton.CountId];  
  MenuItems.Items[SelectedButton.CountId] = MenuItems.Items[SelectedButton.CountId + 1];  
  MenuItems.Items[SelectedButton.CountId + 1] = TempButton;  
  </code></pre>
  
  <p><code>MenuItems.Items</code> is an array of <code>MenuItem</code></p>
  
  <p>Looking at the Watch I have placed on MenuItems.Items, nothing happens on Line 2 or 3.</p>
  
  <p>The <code>MenuItems.Items</code> property has get and set functions, which may be causing the issue... Will investigate further...</p>