Home > Backend Development > C#.Net Tutorial > Hash tables and dictionaries in C#

Hash tables and dictionaries in C#

WBOY
Release: 2023-09-10 23:29:08
forward
702 people have browsed it

C# 中的哈希表与字典

Hash table

A hash table is used when a key is needed to access an element, and useful key values ​​can be identified. Each item in the hash table has a key/value pair. Keys are used to access items in the collection.

Members in the hash table are thread-safe. If we try to find a key that doesn't exist, it will return null. Hashtable is not a generic type.

Hashtable collection is slower than dictionary because it requires boxing and unboxing.

Declaration Hashtable -

Hashtable ht = new Hashtable();
Copy after login

Dictionary

A dictionary is a collection of keys and values ​​in C#. Dictionary is contained in the System.Collection.Generics namespace. Dictionary is a generic type and will return an error if you try to find a key that doesn't exist.

Dictionary collections are faster than Hashtables because there is no boxing and unboxing.

Declare a dictionary -

IDictionary<int, string> d = new Dictionary<int, string>();
Copy after login

The above is the detailed content of Hash tables and dictionaries 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