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.

3
  • 1
    Iterate through the collection and find the value, then try to remove the pair based on the key you found. Commented Oct 30, 2015 at 19:40
  • 1
    Removing a value? What if there are many? Commented Oct 30, 2015 at 19:43
  • 1
    "Token" sounds like pretty unique value Commented Oct 30, 2015 at 19:48

1 Answer 1

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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.