I need to remove multiple items from a Dictionary. A simple way to do that is as follows :
List keystoremove= new List();
for
you can create an extension method:
public static class DictionaryExtensions
{
public static void RemoveAll(this IDictionary dict,
Func predicate)
{
var keys = dict.Keys.Where(k => predicate(dict[k])).ToList();
foreach (var key in keys)
{
dict.Remove(key);
}
}
}
...
dictionary.RemoveAll(x => x.Member == foo);