DictionaryExtensions.Where<TKey, TValue>

Extension Method in DictionaryExtensions

Declaration

public static Dictionary<TKey, TValue> Where<TKey, TValue>(this Dictionary<TKey, TValue> dictionary, Predicate<KeyValuePair<TKey, TValue>> predicate)

Description

Filters the dictionary by a predicate.

Type Parameters

TKeyThe type of the keys in the dictionary.
TValueThe type of the values in the dictionary.

Parameters

dictionaryThe dictionary to filter.
predicateThe predicate to use.

Returns

DictionaryTA new dictionary with the filtered key-value pairs removed.

Overload

Declaration

public static List<TKey> Where<TKey, TValue>(this Dictionary<TKey, TValue>.KeyCollection keys, Predicate<TKey> predicate)

Description

Filters the dictionary keys by a predicate.

Type Parameters

TKeyThe type of the keys in the dictionary.
TValueThe type of the values in the dictionary.

Parameters

keysThe keys to filter.
predicateThe predicate to use.

Returns

ListTA new list with the filtered keys removed.

Overload

Declaration

public static List<TValue> Where<TKey, TValue>(this Dictionary<TKey, TValue>.ValueCollection values, Predicate<TValue> predicate)

Description

Filters the dictionary values by a predicate.

Type Parameters

TKeyThe type of the keys in the dictionary.
TValueThe type of the values in the dictionary.

Parameters

valuesThe values to filter.
predicateThe predicate to use.

Returns

ListTA new list with the filtered values removed.