Próbowałem napisać metodę rozszerzenia do naśladowania List.RemoveAll (Predicate).Metody rozszerzające Słownik: <TKey,TValue> .RemoveAll? Czy to możliwe?
Do tej pory mam to:
public static void RemoveAll<TKey,TValue>(this Dictionary<TKey,TValue> dict,
Predicate<KeyValuePair<TKey,TValue>> condition)
{
Dictionary<TKey,TValue> temp = new Dictionary<TKey,TValue>();
foreach (var item in dict)
{
if (!condition.Invoke(item))
temp.Add(item.Key, item.Value);
}
dict = temp;
}
Wszelkie wskazówki? Czy jest to całkowicie naiwna implementacja?
Czy nie chcesz usunąć pary ze słownika, jeśli twój predykat pasuje tylko do klucza, zamiast do KeyValuePair? – base2