Skip to content

M_CodeJam_Collections_EnumerableExtensions_ToDictionary__2_1

Andrew Koryavchenko edited this page Jun 17, 2018 · 1 revision

EnumerableExtensions.ToDictionary(T, TKey) Method (IEnumerable(T), Func(T, TKey), IEqualityComparer(TKey), DictionaryDuplicate)

Creates a Dictionary(TKey, TValue) from an IEnumerable(T) according to a specified key selector function, a comparer and a duplicate handling policy.

Namespace: CodeJam.Collections
Assembly: CodeJam (in CodeJam.dll) Version: 2.1.0.0

Syntax

C#

public static Dictionary<TKey, T> ToDictionary<T, TKey>(
	this IEnumerable<T> source,
	Func<T, TKey> keySelector,
	IEqualityComparer<TKey> comparer,
	DictionaryDuplicate duplicateHandling
)

VB

<ExtensionAttribute>
Public Shared Function ToDictionary(Of T, TKey) ( 
	source As IEnumerable(Of T),
	keySelector As Func(Of T, TKey),
	comparer As IEqualityComparer(Of TKey),
	duplicateHandling As DictionaryDuplicate
) As Dictionary(Of TKey, T)

F#

[<ExtensionAttribute>]
static member ToDictionary : 
        source : IEnumerable<'T> * 
        keySelector : Func<'T, 'TKey> * 
        comparer : IEqualityComparer<'TKey> * 
        duplicateHandling : DictionaryDuplicate -> Dictionary<'TKey, 'T> 

Parameters

 

source
Type: System.Collections.Generic.IEnumerable(T)
An IEnumerable(T) to create a Dictionary(TKey, TValue) from.
keySelector
Type: System.Func(T, TKey)
A function to extract a key from each element.
comparer
Type: System.Collections.Generic.IEqualityComparer(TKey)
An IEqualityComparer(T) to compare keys.
duplicateHandling
Type: CodeJam.Collections.DictionaryDuplicate
Policy for duplicate handling.

Type Parameters

 

T
The type of the elements of source.
TKey
The type of the key returned by keySelector.

Return Value

Type: Dictionary(TKey, T)
A Dictionary(TKey, TValue) that contains keys and values.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type IEnumerable(T). 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).

See Also

Reference

EnumerableExtensions Class
ToDictionary Overload
CodeJam.Collections Namespace

Clone this wiki locally