4

I have a concurrent dictionary with Ids as keys and tokens as values. There are instances where I will have an Id for which I want to remove tokens, and there are instances where I will have a specific token to remove. What could I call on the dictionary to find the pair with a specified value?

Tokens are unique to Ids.

paulina
  • 199
  • 3
  • 14

1 Answers1

5

What about searching the values and remove them in a loop?

var itemsToRemove = dictionary.Where(kvp => kvp.Value.Equals(token));
foreach (var item in itemsToRemove)
   dictionary.TryRemove(item.Key, out token);
Bruno Leupi
  • 116
  • 4