728x90 AdSpace

  • Latest News

    Thursday, 2 November 2017

    [Knowledge] Differences between Hashtable and Dictionary

    This topic today is talk about Hashtable and Dictionary. We'll easy to understand and notice that 2 kinds data structure. Ok let's take a look

    Hashtable

     
    In computing, a hash table (hash map) is a data structure which implements an associative array abstract data type, a structure that can map keys to values. A hash table uses a hash function to compute an index into an array of buckets or slots, from which the desired value can be found.

    Differences between Hashtable and Dictionary





    Dictionary


    A dictionary uses a key to reference the value directly inside of an associative array.
    In computer science, an associative array, map, symbol table, or dictionary is an abstract data type composed of a collection of (key, value) pairs, such that each possible key appears at most once in the collection.

    Differences between Hashtable and Dictionary




    Now, what differences between Hashtable and Dictionary


    Dictionary:
    • It returns/throws Exception if we try to find a key which does not exist.
    • It is faster than a Hashtable because there is no boxing and unboxing.
    • Only public static members are thread safe.
    • Dictionary is a generic type which means we can use it with any data type (When creating, must specify the data types for both keys and values).
      Example: Dictionary<string, string> <NameOfDictionaryVar> = new Dictionary<string, string>();
    • Dictionay is a type-safe implementation of Hashtable, Keys and Values are strongly typed.
    Hashtable:
    • It returns null if we try to find a key which does not exist.
    • It is slower than dictionary because it requires boxing and unboxing.
    • All the members in a Hashtable are thread safe,
    • Hashtable is not a generic type,
    • Hashtable is loosely-typed data structure, we can add keys and values of any type.
    • Blogger Comments
    • Facebook Comments

    0 comments:

    Post a Comment

    Item Reviewed: [Knowledge] Differences between Hashtable and Dictionary Rating: 5 Reviewed By: Unknown
    Scroll to Top