I have a Class. I'm creating a List of items that are based on that class. Like, Class Fruit and List<Fruit> fruits. Now, I'm creating another List for the same Class type. Is there a simple straight instruction (method/function) to order the items in the second List based on the index they have in the first main List?
Like, I don't want to order them in alphabetical order or such basic concepts, I want to have a specific order of the items in the first List and when I finish creating the second List, which items are all contained in the first List, I want to order the items in this new List like they would be ordered in the first one (so, basically, by their index).
Note that in this second List the items can occur more than once. A useful info can be the fact that, for example, a Fruit can have a name property (if a property is needed to do this).
So if my first List is just a general List of Fruit, having each one a name, like,
fruits[0] -> item having name "Strawberry"
fruits[1] -> item having name "Banana"
fruits[2] -> item having name "Pear"
and my second list will be like
secList[0] -> item having name "Pear"
secList[1] -> item having name "Strawberry"
secList[2] -> item having name "Banana"
secList[3] -> item having name "Banana"
i want the second list to become ordered like this:
secList[0] -> item having name "Strawberry"
secList[2] -> item having name "Banana"
secList[3] -> item having name "Banana"
secList[1] -> item having name "Pear"
Like, I don't want to order them in alphabetical order or such basic concepts, I want to have a specific order of the items in the first List and when I finish creating the second List, which items are all contained in the first List, I want to order the items in this new List like they would be ordered in the first one (so, basically, by their index).
Note that in this second List the items can occur more than once. A useful info can be the fact that, for example, a Fruit can have a name property (if a property is needed to do this).
So if my first List is just a general List of Fruit, having each one a name, like,
fruits[0] -> item having name "Strawberry"
fruits[1] -> item having name "Banana"
fruits[2] -> item having name "Pear"
and my second list will be like
secList[0] -> item having name "Pear"
secList[1] -> item having name "Strawberry"
secList[2] -> item having name "Banana"
secList[3] -> item having name "Banana"
i want the second list to become ordered like this:
secList[0] -> item having name "Strawberry"
secList[2] -> item having name "Banana"
secList[3] -> item having name "Banana"
secList[1] -> item having name "Pear"