It works with generic collections and uses Comparer.Default to determine equality of contained elements. The asymptotic behavior of the method below is quadratic, which is why I previously called it naive.
Anyway, I think if you need a simple solution and don't have very stringent performance requirements (e.g. writing unit tests), the code below might help you.
bool Compare<T>(ICollection<T> one, ICollection<T> two) {
if (one == null || two == null) // special case
return one == two;
if (ReferenceEquals(one, two)) // same objects
return true;
if (one.Count != two.Count)
return false;
IList listOne = new List<T>(one);
IList listTwo = new List<T>(two);
// make sure that every object in one is also in two
for (int i = 0; i < listOne.Count; i++) {
object obj = listOne[i];
if (!listTwo.Contains(obj))
return false;
else
listTwo.Remove(obj);
}
return true;
}