DictionaryUtility.AsReadOnlyDictionary<TKey,TValue> method

Represents the sequence of key-value pairs as a IReadOnlyDictionary.

public static IReadOnlyDictionary<TKey, TValue> AsReadOnlyDictionary<TKey, TValue>(
    this IEnumerable<KeyValuePair<TKey, TValue>> keyValuePairs)
parameter description
TKey The type of the key.
TValue The type of the value.
keyValuePairs The key-value pairs.

Return Value

A IReadOnlyDictionary containing the key-value pairs in the sequence.

Remarks

If the sequence is an IReadOnlyDictionary, it is returned directly. If it is an IDictionary, an adapter is created to wrap it. Otherwise, the sequence is copied into a Dictionary and then wrapped in a ReadOnlyDictionary. This method is useful for forcing evaluation of a potentially lazy sequence while retaining reasonable performance for sequences that are already an IReadOnlyDictionary or IDictionary.

See Also