What is the best data structure in .NET for look-u

2019-03-28 05:40发布

I'm looking for the most ideal data structure (for performance and ease of use) from which values can be retrieved by string key or index. Dictionary doesn't work because you can't really retrieve by index. Any ideas?

7条回答
混吃等死
2楼-- · 2019-03-28 06:27

Hash based collections (Dictionary, Hashtable, HashSet) are out because you won't have an index, since you want an index, I'd use a nested generic:

List<KeyValuePair<K,V>>

Of course, you lose the O(1) Key lookup that you get with hashes.

查看更多
登录 后发表回答