C# associative array

后端 未结 10 2155
时光取名叫无心
时光取名叫无心 2020-12-11 00:12

I\'ve been using a Hashtable, but by nature, hashtables are not ordered, and I need to keep everything in order as I add them (because I want to pull them out in the same or

10条回答
  •  不思量自难忘°
    2020-12-11 01:01

    EDIT: LBushkin is right - OrderedDictionary looks like it does the trick, albeit in a non-generic way. It's funny how many specialized collections there are which don't have generic equivalents :( (It would make sense for Malfist to change the accepted answer to LBushkin's.)

    (I thought that...) .NET doesn't have anything built-in to do this.

    Basically you'll need to keep a List as well as a Dictionary. When you add to the dictionary, add the key to the list. Then you can iterate through the list and find the keys in insertion order. You'll need to be careful when you remove or replace items though.

提交回复
热议问题