The struct below consists of three variables, bool visible, int id, and int order.
List<Data.myStruct> itemList = new List<Data.myStruct>();
Then I add four items to the list
itemList.Add(new Data.myStruct(false, 1, 0));
itemList.Add(new Data.myStruct(false, 2, 0));
itemList.Add(new Data.myStruct(false, 3, 0));
itemList.Add(new Data.myStruct(false, 4, 0));
I can make a function to set the visibility of a given id to true.
public void setVisible(int id) {
for(int i = 0; i < itemList.Count; i++)
{
if(id == itemList[i].id)
{
itemList[i] = new Data.myStruct(true, itemList[i].id, itemList[i].order);
}
}
}
My question would be this, How would I be able to set the order of each item in the itemList when bool visible = true based on when setVisible(int id) is called. So if setVisible(1) is called before setVisible(2) then the order of the second one would be greater than the first one, or vice versa.
For Example,
setVisible(1);
setVisible(2);
Result:
itemList[0].visible = true, itemList[0].id = 1, itemList[0].order = 1
itemList[1].visible = true, itemList[1].id = 2, itemList[1].order = 2
itemList[2].visible = false, itemList[2].id = 3, itemList[2].order = 0
itemList[3].visible = false, itemList[3].id = 4, itemList[3].order = 0
And if I were to change the visibility to false on one of them, How might I change the order to fill in the gap. Can this be done using linq?
Edit:
How would I be able to loop through the list by order of highest order value?