# how to compare the order of the objects of list

I have two lists named gems and gems1 in which I have 16 clones of an object, and they are stored with unique names in both lists. Afterward one list gets shuffled. Now I want to compare the order of the objects in both . How do I do that…??

for(int a=GridHeight;a>0;a--){
for(int b=0;b<GridWidth;b++)
{
g =  Instantiate(gemprefab, new Vector3 ( b,a, 0), Quaternion.identity) as GameObject;

g.name= "gem"+ t;
g.transform.parent = gameObject.transform;

LastGem=g.GetComponent<Gem>();

gemComponent = g.GetComponent<Gem>();
t++;
}
for(int i = 0; i < gems.Count; i++) {
Vector3 temp = gems*.transform.position;*

randomIndex = Random.Range(0, gems.Count);
gems*.transform.position = gems[randomIndex].transform.position;*
gems[randomIndex].transform.position = temp;
//print (gems*);*
//print (gems1*);*
}
}
void comp()

{
for (int i = 0; i < gems.Count; i++) {
for (int j = 0; j< gems1.Count; j++) {

if(gems*.transform.name.StartsWith(gems1[j].transform.name))*
{
break;
//print (“gems*.transform.name”);*
//print (“gems1*.transform.name”);*

}

}

You can use linq and SequenceEqual extension to compare the order of two Lists.

using System.Linq;
// Other usings/class declaration, methods, fields.....
// ...
// ...
bool CompareGems()
{
return gems.SequenceEqual(gems1); // SequenceEqual extention returns boolean or true/false.
}