I need to remove multiple items from a Dictionary. A simple way to do that is as follows :
List keystoremove= new List();
for
Instead of removing, just do the inverse. Create a new dictionary from the old one containing only the elements you are interested in.
public Dictionary NewDictionaryFiltered
(
Dictionary source,
Func filter
)
{
return source
.Where(x => filter(x.Key, x.Value))
.ToDictionary(x => x.Key, x => x.Value);
}