Fastest way to find out whether two ICollection<T> collections contain the same objects

What is the fastest way to find out whether two ICollection<T> collections contain precisely the same entries? Brute force is clear, I was wondering if there is a more elegant method.

We are using C# 2.0, so no extension methods if possible, please!

Edit: the answer would be interesting both for ordered and unordered collections, and would hopefully be different for each.


use C5


" Check if all items in a supplied collection is in this bag (counting multiplicities). The items to look for. True if all items are found."


public virtual bool ContainsAll<U>(SCG.IEnumerable<U> items) where U : T
  HashBag<T> res = new HashBag<T>(itemequalityComparer);

  foreach (T item in items)
    if (res.ContainsCount(item) < ContainsCount(item))
      return false;

  return true;

Need Your Help

How to mock protected subclass method inherited from abstract class?

java unit-testing junit mockito powermock

How to use Mockito or PowerMock to mock a protected method that is realized by a subclass, but inherited from an abstract super class?

JUnit test report enrichment with JavaDoc

java unit-testing junit automated-tests integration-testing

For a customer we need to generate detailed test reports for integration tests which not only show, that everything is green, but also what the test did. My colleagues and I are lazy guys and we do...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.