in Technology by
Why is Dictionary preferred over Hashtable in C#?

1 Answer

0 votes
by

If you meant "why do we use the Dictionary<TKey, TValue> class instead of the Hashtable class?", then it's an easy answer: Dictionary<TKey, TValue> is a generic type, Hashtable is not. That means you get type safety with Dictionary<TKey, TValue>, because you can't insert any random object into it, and you don't have to cast the values you take out.

Interestingly, the Dictionary<TKey, TValue> implementation in the .NET Framework is based on the Hashtable, as you can tell from this comment in its source code:

The generic Dictionary was copied from Hashtable's source

Related questions

0 votes
    Why Tableau is preferred over other ?...
asked Oct 29, 2020 in Technology by JackTerrance
0 votes
    Which of these is the interface of legacy is implemented by Hashtable and Dictionary classes? (a) Map (b) ... Framework of Java Select the correct answer from above options...
asked Mar 1, 2022 in Education by JackTerrance
0 votes
    Which of these is the interface of legacy is implemented by Hashtable and Dictionary classes? (a) Map (b ... questions and answers pdf, java interview questions for beginners...
asked Oct 25, 2021 in Education by JackTerrance
0 votes
    When and why is molality preferred over molarity in handling solution in CHMemistry? Select the correct answer from above options...
asked Jan 5, 2022 in Education by JackTerrance
0 votes
    Why instantaneous rate is preferred over average rate? Select the correct answer from above options...
asked Jan 4, 2022 in Education by JackTerrance
0 votes
    What is a Hashtable in C#?...
asked Apr 1, 2021 in Education by JackTerrance
0 votes
    _____________ function is preferred over sapply as vapply allows the programmer to specific the output type. (a) ... of R Programming Select the correct answer from above options...
asked Feb 15, 2022 in Education by JackTerrance
0 votes
    What is the best way to iterate over a dictionary?...
asked Jan 15, 2021 in Technology by JackTerrance
0 votes
    Why is NumPy preferred to other programming tools such as Idl, Matlab, Octave, Or Yorick?...
asked Apr 24, 2021 in Technology by JackTerrance
0 votes
    Why is this keyword not preferred in JavaScript? (a) Highly memory consuming (b) Functions should access ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Oct 23, 2021 in Education by JackTerrance
0 votes
    Why the balanced draught system is preferred than other system?...
asked Feb 2, 2021 in General by JackTerrance
0 votes
    Is there a way to test if an object is a dictionary? In a method I'm trying to get a value ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 20, 2022 in Education by JackTerrance
0 votes
    Is there a way to test if an object is a dictionary? In a method I'm trying to get a value ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 20, 2022 in Education by JackTerrance
0 votes
    Is there a way to test if an object is a dictionary? In a method I'm trying to get a value ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 20, 2022 in Education by JackTerrance
0 votes
    Is there a way to test if an object is a dictionary? In a method I'm trying to get a value ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 19, 2022 in Education by JackTerrance
...