Is there an implementation of IList <T> where Contains (T) is an O (1) operation?
7 answers
You can implement it IList<T>yourself and save two support collections - a List<T>and a HashSet<T>. Basically, for Visual Studio to provide an “exception exception” implementation for everything in IList<T>, then for each method, find out if you want to proxy it in a list or in a set.
Of course, you have to be careful with duplicates, etc. (define behavior Add(x), Add(x), Remove(x), Contains(x)- you can be on the list but not in the set) but it would not be too difficult.
+3
There is a new class in .NET 4 SortedSet<T>where Contains()- O (1), see this MSDN page
+1