daily pastebin goal
70%
SHARE
TWEET

Untitled

a guest Dec 16th, 2018 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System.Collections.Concurrent;
  2.  
  3. class ConcurrentDictionary
  4. {
  5.     static void Main(string[] args)
  6.     {
  7.         ConcurrentDictionary<int, string> dict = new ConcurrentDictionary<int, string>();
  8.         dict.TryAdd(1, "January");   //returns true
  9.         dict.TryAdd(2, "February");  //returns true
  10.         dict.TryAdd(3, "March");     //returns true
  11.         dict.TryAdd(4, "Apr");     //returns true
  12.  
  13.         string updatedValue;
  14.         bool returnTrue = dict.TryUpdate(4, "April", "Apr"); //Returns true
  15.         dict.TryGetValue(4, out updatedValue);
  16.         Console.WriteLine(updatedValue); //Display "April"
  17.  
  18.         bool returnsFalse = dict.TryUpdate(4, "Apr", "Apr"); //Returns false
  19.         dict.TryGetValue(4, out updatedValue);  //Returns "April" Old value
  20.         Console.WriteLine(updatedValue);    //Returns "April"
  21.     }
  22. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top