/// <summary> /// Removes all items matched by predicate /// Returns number of items removed /// </summary> /// <param name="dic"></param> /// <param name="predicate"></param> /// <typeparam name="K"></typeparam> /// <typeparam name="V"></typeparam> /// <returns></returns> public static int RemoveAll <K, V>(this IDictionary <K, V> dic, Func <KeyValuePair <K, V>, bool> predicate) { predicate.MustNotBeNull(); dic.MustNotBeNull(); var keys = dic.TakeWhile(predicate).ToArray(); foreach (var kv in keys) { dic.Remove(kv); } return(keys.Length); }