.NET Fiddle

CSharp · Console

/Program.cs

using System;
using System.Collections.Concurrent;
using System.Reflection;
					
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,
		TValue comparand)
	{
		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);
		value = (TValue)args[1];
		return (bool)result;
	}
}
;