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:
MenuItem Temp = Items[2];
Items[2] = Items[3];
Items[3] = Temp;
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?
Edited - Sorry. Looks like I made a mess of the code when trying to clean it up for posting. Corrected now.
The actual code is :
MenuItem TempButton = MenuItems.Items[SelectedButton.CountId];
MenuItems.Items[SelectedButton.CountId] = MenuItems.Items[SelectedButton.CountId + 1];
MenuItems.Items[SelectedButton.CountId + 1] = TempButton;
MenuItems.Items
is an array of MenuItem
Looking at the Watch I have placed on MenuItems.Items, nothing happens on Line 2 or 3.
The MenuItems.Items
property has get and set functions, which may be causing the issue... Will investigate further...