HashSet的是preserves订购的是、HashSet、preserves

2023-09-02 01:42:33 作者:相见

我需要一个HashSet的是preserves插入排序,还有这实现任何框架中的?

I need a HashSet that preserves insertion ordering, are there any implementations of this in the framework?

推荐答案

您可以用得到这个功能,很容易 KeyedCollection< TKEY的,TItem> 指定相同类型参数TKEY的和TItem:

You can get this functionality easily using KeyedCollection<TKey,TItem> specifying the same type argument for TKey and TItem:

public class OrderedHashSet<T> : KeyedCollection<T, T>
{
    protected override T GetKeyForItem(T item)
    {
        return item;
    }
}