.NET Framework Class Library
EnumerableToDictionaryTSource, TKey, TElement Method (IEnumerableTSource, FuncTSource, TKey, FuncTSource, TElement)

Creates a DictionaryTKey, TValue from an IEnumerableT according to specified key selector and element selector functions.

Namespace:   System.Linq
Assemblies:   System.Linq (in System.Linq.dll)
  System.Core (in System.Core.dll)
<[%$TOPIC/bb548657_en-us_VS_110_3_0_0_0_0%]> _
Public Shared Function ToDictionary(Of TSource, TKey, TElement) ( _
	source As [%$TOPIC/bb548657_en-us_VS_110_3_0_0_0_1%](Of TSource), _
	keySelector As [%$TOPIC/bb548657_en-us_VS_110_3_0_0_0_2%](Of TSource, TKey), _
	elementSelector As [%$TOPIC/bb548657_en-us_VS_110_3_0_0_0_3%](Of TSource, TElement) _
) As [%$TOPIC/bb548657_en-us_VS_110_3_0_0_0_4%](Of TKey, TElement)
public static [%$TOPIC/bb548657_en-us_VS_110_3_0_1_0_0%]<TKey, TElement> ToDictionary<TSource, TKey, TElement>(
	this [%$TOPIC/bb548657_en-us_VS_110_3_0_1_0_1%]<TSource> source,
	[%$TOPIC/bb548657_en-us_VS_110_3_0_1_0_2%]<TSource, TKey> keySelector,
	[%$TOPIC/bb548657_en-us_VS_110_3_0_1_0_3%]<TSource, TElement> elementSelector
generic<typename TSource, typename TKey, typename TElement>
static [%$TOPIC/bb548657_en-us_VS_110_3_0_2_0_1%]<TKey, TElement>^ ToDictionary(
	[%$TOPIC/bb548657_en-us_VS_110_3_0_2_0_2%]<TSource>^ source, 
	[%$TOPIC/bb548657_en-us_VS_110_3_0_2_0_3%]<TSource, TKey>^ keySelector, 
	[%$TOPIC/bb548657_en-us_VS_110_3_0_2_0_4%]<TSource, TElement>^ elementSelector
static member ToDictionary : 
        source:[%$TOPIC/bb548657_en-us_VS_110_3_0_3_0_0%]<'TSource> * 
        keySelector:[%$TOPIC/bb548657_en-us_VS_110_3_0_3_0_1%]<'TSource, 'TKey> * 
        elementSelector:[%$TOPIC/bb548657_en-us_VS_110_3_0_3_0_2%]<'TSource, 'TElement> -> [%$TOPIC/bb548657_en-us_VS_110_3_0_3_0_3%]<'TKey, 'TElement> 

Type Parameters


The type of the elements of source.


The type of the key returned by keySelector.


The type of the value returned by elementSelector.


Type: System.Collections.GenericIEnumerableTSource

An IEnumerableT to create a DictionaryTKey, TValue from.

Type: SystemFuncTSource, TKey

A function to extract a key from each element.

Type: SystemFuncTSource, TElement

A transform function to produce a result element value from each element.

Return Value

Type: System.Collections.GenericDictionaryTKey, TElement
A DictionaryTKey, TValue that contains values of type TElement selected from the input sequence.

Usage Note

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

source or keySelector or elementSelector is .


keySelector produces a key that is .


keySelector produces duplicate keys for two elements.


The ToDictionaryTSource, TKey, TElement(IEnumerableTSource, FuncTSource, TKey, FuncTSource, TElement) method uses the default equality comparer Default to compare keys.

Version Information

.NET Framework

Supported in: 4.6, 4, 3.5

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

Supported in: Windows Phone 8.1

Supported in: Windows Phone Silverlight 8.1

Supported in: Windows Phone Silverlight 8

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.