When to use a HashTable

后端 未结 8 937
眼角桃花
眼角桃花 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:50

    You use a hashtable (dictionary) when you want fast look up access to an item based on a key.

    If you are using List, IList or IEnumerable generally this means that you are looping over data (well in the case of IEnumerable it definitely means that), and a hashtable isn't going to net you anything. Now if you were looking up a value in one list and using that to access data in another list, that would a little different. For example:

    1. Find position in list of Item foo.
    2. Position in list for foo corresponds to position in another list which contains Foo_Value.
    3. Access position in seconds list to get Foo_Value.

    Here is a link describing the different datatypes.

    Another link.

提交回复
热议问题