Click here to Skip to main content
Click here to Skip to main content

Tagged as

Go to top

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

, 27 Sep 2013
Rate this:
Please Sign up or sign in to 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:

  1. Creates Key-Value pair hashtable.
  2. 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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

No Biography provided

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web03 | 2.8.140916.1 | Last Updated 27 Sep 2013
Article Copyright 2013 by Member 10298658
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid