Question: I have a dictionary collection as bleow:

```
mydic.addvalue(key1, val1)
mydic.addvalue(key2, val1)
mydic.addvalue(key3, val1)
mydic.addvalue(key4, val2)
mydic.addvalue(key5, val2)

```

From the above dictionary I want to delete all the entries where value == "val1", so that the result would have only following entry:

```
mydic.addvalue(key4, val2)
mydic.addvalue(key5, val2)

```

My VB source code is on VS2008 and targeted for 3.5

Answer: 
You first need to find all keys for which the associated value is `val1`:

```
var keysToRemove = mydic.Where(kvp => kvp.Value == val1)
                        .Select(kvp => kvp.Key)
                        .ToArray();

```

Then you can remove each of those keys:

```
foreach (var key in keysToRemove)
{
    mydic.Remove(key);
}

```
The answer it's old but this is how I do the same thing without create another Dictionary.

```
foreach (KeyValuePair<TKey, TValue> x in MyDic) {

  if (x.Value == "val1")) 
  {  MyDic.Remove(x.Key); } 
}

```