Generic collection with IEqualityComparer in constructor
Is there any collection in framework like that?
public class DesiredCollection<T>
{
public DesiredCollection(IEqualityComparer<T> comparer)
{
}
}
Requirements:
- generic collection;
- I开发者_开发知识库EqualityComparer or lambda-expression to determine equality;
- no need to define key type;
- getting item by key;
- getting all items as IEnumerable.
Various collections take IEqualityComparer<T>
in their constructors (usually as one overload out of several). In particular, Dictionary<TKey, TValue>
and HashSet<T>
fall into this category. They use the equality comparer to check for the existence of keys / elements.
However, you haven't really expressed anything other than the need for a constructor taking an equality comparer. Presumably you'll need more than that... what are you trying to do?
精彩评论