Combining Items in a single list by comparison

Hi I have a list of items in which a bunch of them are effectively duplicates. I need to compare each item to every other item to see if the they are a match on the correct fields e.g. for a Transform (although my items are not MonoBehaviours)do 2 transforms share the same name, scale and rotation [ignoring position etc] I’ve tried reverse looping but it seams to miss many items and cant seam to find another way to do it without causing an infinite loop here’s what I’m sort of using at the moment

		for (int i = Items.Count - 1; i > 0; i--)
			for (int j = Items.Count - 1; j > 0; j--)
				if (Items<em>.A == Items[j].A && Items_.B == Items[j].B && Items*.C == Items[j].D)*_</em>

* {*
_ Item b1 = Items*;
Item b2 = Items[j];
Item b = new Item ( b1.A,b1.B,b1.C,b1.D+b2.D);
Items.Insert (0, b);
Items.Remove (b1);
Items.Remove (b2);

I’ve been searching for a solution and seam to find a lot of things mentioning “LinQ” but until a few hours ago id never heard of it and the tutorials I’ve found don’t seam to be have any knowledge I can easily rip out to make this work. Also just to note this wont be running to often [maybe 1-2 times in extreme cases] so shouldn’t be to much of a problem if the solution is resource heavy. any help would be greatly appreciated._

This ended up being more in depth than I planned, but here’s how you can use two lists to do the combination as you have set up.

List<Object> toRemove;
List<Object> toAdd;

for(int i = 0; i < originalList.Count; ++i)
	Object obj1 = originalList*;*
  • if (toRemove.Contains(obj1))*
  •  continue;*
  • bool beenAdded = false;*
  • Object newVal;*
  • for(int j = i + 1; j < originalList.Count; ++j)*
  • {*
  •  Object obj2 = originalList[j];*
  •  if (ShouldCombine(obj1, obj2))*
  •  {*
  •  	toRemove.AddUnique(obj2);*
  •  	if (!beenAdded)*
  •  	{*
  •  		toRemove.AddUnique(obj1);*
  •  		newVal = Combine(obj1, obj2);*
  •  	}*
  •  	else*
  •  		newVal = Combine(newVal, obj2);*

beenAdded = true;

  •  }*
  • }*
  • if (beenAdded)*
  •  toAdd.Add(newVal);*


foreach(Object removedObj in toRemove)

  • originalList.Remove(removedObj);*
    foreach(Object newObj in toAdd)
  • originalList.Add(newObj);*