Why is Dictionary preferred over Hashtable in C#?

后端 未结 19 1448
长情又很酷
长情又很酷 2020-11-22 05:53

In most programming languages, dictionaries are preferred over hashtables. What are the reasons behind that?

19条回答
  •  萌比男神i
    2020-11-22 06:37

    According to what I see by using .NET Reflector:

    [Serializable, ComVisible(true)]
    public abstract class DictionaryBase : IDictionary, ICollection, IEnumerable
    {
        // Fields
        private Hashtable hashtable;
    
        // Methods
        protected DictionaryBase();
        public void Clear();
    .
    .
    .
    }
    Take note of these lines
    // Fields
    private Hashtable hashtable;
    

    So we can be sure that DictionaryBase uses a HashTable internally.

提交回复
热议问题