Click here to Skip to main content
12,628,277 members (35,122 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

4.7K views
4 bookmarked
Posted

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

, 27 Sep 2013 CPOL
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

You may also be interested in...

Comments and Discussions

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