When to use a HashTable

后端 未结 8 783
眼角桃花
眼角桃花 2020-12-24 02:13

In C#, I find myself using a List, IList or IEnumerable 99% of the time. Is there a case when it would be b

相关标签:
8条回答
  • 2020-12-24 02:59

    I use Hashtables quite often to send back key/value collections to Javascript via page methods.

    Dictionaries are good for caching things when you need to retrieve an object given its ID but don't want to have to hit the database: Assuming your collection is not large enough to induce a large number of collisions and your data needs retrieving often enough for an IEnumerable to be too slow, Dictionaries can give a decent speed-up.

    0 讨论(0)
  • 2020-12-24 03:01

    Hash-tables are good choices if you are often doing "for something in collection" and you aren't concerned about the order of items in the collection.

    Hash-tables are indexes. You can maintain a hash-table to index a list, so you can both choice to access it in order or randomly based upon the key.

    0 讨论(0)
提交回复
热议问题