Home > Backend Development > C#.Net Tutorial > Why are dictionaries preferred over hash tables in C#?

Why are dictionaries preferred over hash tables in C#?

王林
Release: 2023-08-28 16:29:02
forward
655 people have browsed it

为什么在 C# 中字典比哈希表更受青睐?

The Hashtable class represents a collection of key-value pairs organized according to the hash code of the key. It uses keys to access elements in the collection.

A dictionary is a collection of keys and values ​​in C#. Dictionary is contained in the System.Collection.Generics namespace.

Hashtable is slower than Dictionary. For strongly typed collections, Dictionary collections are faster.

Suppose we need to find a key from a Hashtable collection. This way, we can also find a key from the Dictionary collection. In this case, for the same statement, dictionary will be faster -

for HashTable

hashtable.ContainsKey("12345");
Copy after login

for Dictionary

dictionary.ContainsKey("12345")
Copy after login

The above is the detailed content of Why are dictionaries preferred over hash tables in C#?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template