Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

ImmutableDictionary.ToImmutableDictionary<TSource, TKey, TValue> Method (IEnumerable<TSource>, Func<TSource, TKey>, Func<TSource, TValue>, IEqualityComparer<TKey>, IEqualityComparer<TValue>)

Enumerates and transforms a sequence, and produces an immutable dictionary of its contents by using the specified key and value comparers.

Namespace:  System.Collections.Immutable
Assembly:  System.Collections.Immutable (in System.Collections.Immutable.dll)

public static ImmutableDictionary<TKey, TValue> ToImmutableDictionary<TSource, TKey, TValue>(
	this IEnumerable<TSource> source,
	Func<TSource, TKey> keySelector,
	Func<TSource, TValue> elementSelector,
	IEqualityComparer<TKey> keyComparer,
	IEqualityComparer<TValue> valueComparer

Type Parameters


The type of the elements in the sequence.


The type of the keys in the resulting dictionary.


The type of the values in the resulting dictionary.


Type: System.Collections.Generic.IEnumerable<TSource>

The sequence to enumerate to generate the dictionary.

Type: System.Func<TSource, TKey>

The function that will produce the key for the dictionary from each sequence element.

Type: System.Func<TSource, TValue>

The function that will produce the value for the dictionary from each sequence element.

Type: System.Collections.Generic.IEqualityComparer<TKey>

The key comparer to use for the dictionary.

Type: System.Collections.Generic.IEqualityComparer<TValue>

The value comparer to use for the dictionary.

Return Value

Type: System.Collections.Immutable.ImmutableDictionary<TKey, TValue>
An immutable dictionary that contains the items in the specified sequence.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type IEnumerable<TSource>. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).
© 2015 Microsoft