Creating Key-Value pair in a dictionary if key is not available





0/5 (0 vote)
The ConcurrentDictionary type resides in System.Collections.Concurrent, introduced in .NET 4.0. It makes adding, removing and updating values in a lookup table on multiple threads easier.
Introduction
The ConcurrentDictionary
type resides in System.Collections.Concurrent
, introduced in .NET 4.0. It makes adding, removing, and updating values in a lookup table on
multiple threads easier.
Background
How to add a Key-Value pair into a dictionary if the key is not available in the dictionary?
Using the code
The ConcurrentDictionary
type resides in System.Collections.Concurrent
, introduced in .NET 4.0. It makes adding, removing and updating values in a
lookup table on multiple threads easier.
Applications of ConcurrentDictionary:
- Creates Key-Value pair hashtable.
- If key is not available in the dictionary adds value into the dictionary.
Code snippet for getting value for a new key.
Customized GetOrAddMethod
to get the status of newly added Key-Value pair.