using System.Collections.Concurrent;
public static class Program
public static void Main()
var dictionary = new ConcurrentDictionary<int, int>();
dictionary.TryAdd(1, 10);
bool removeResult = dictionary.TryRemove(1, out int value, 10);
Console.WriteLine($"Removed: {removeResult}, Value: {value}");
public static bool TryRemove<TKey, TValue>(
this ConcurrentDictionary<TKey, TValue> dictionary, TKey key, out TValue value,
MethodInfo mi = dictionary.GetType().GetMethod("TryRemoveInternal",
BindingFlags.NonPublic | BindingFlags.Instance);
object[] args = new object[] { key, default(TValue), true, comparand };
var result = mi.Invoke(dictionary, args);