HashSet that preserves ordering

后端 未结 3 1391
滥情空心
滥情空心 2020-11-27 05:30

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

3条回答
  •  醉话见心
    2020-11-27 05:38

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

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

提交回复
热议问题