私は、List.RemoveAll(Predicate)を模倣する拡張メソッドを作成しようとしています。拡張メソッド辞書<TKey,TValue> .RemoveAll?出来ますか?
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;
}
任意のポインタ:
は、これまでのところ私はこれを持っていますか?これは完全に素朴な実装ですか?
KeyValuePairの代わりにKeyだけで述語を一致させることで、辞書からペアを削除したくないですか? – base2