Skip to main content
.NET Framework Class Library
EnumerableToLookupTSource, TKey, TElement Method (IEnumerableTSource, FuncTSource, TKey, FuncTSource, TElement, IEqualityComparerTKey)

Creates a LookupTKey, TElement from an IEnumerableT according to a specified key selector function, a comparer and an element selector function.

Namespace:   System.Linq
Assembly:  System.Core (in System.Core.dll)
<[%$TOPIC/bb548544_en-us_VS_110_3_0_0_0_0%]> _
Public Shared Function ToLookup(Of TSource, TKey, TElement) ( _
	source As [%$TOPIC/bb548544_en-us_VS_110_3_0_0_0_1%](Of TSource), _
	keySelector As [%$TOPIC/bb548544_en-us_VS_110_3_0_0_0_2%](Of TSource, TKey), _
	elementSelector As [%$TOPIC/bb548544_en-us_VS_110_3_0_0_0_3%](Of TSource, TElement), _
	comparer As [%$TOPIC/bb548544_en-us_VS_110_3_0_0_0_4%](Of TKey) _
) As [%$TOPIC/bb548544_en-us_VS_110_3_0_0_0_5%](Of TKey, TElement)
public static [%$TOPIC/bb548544_en-us_VS_110_3_0_1_0_0%]<TKey, TElement> ToLookup<TSource, TKey, TElement>(
	this [%$TOPIC/bb548544_en-us_VS_110_3_0_1_0_1%]<TSource> source,
	[%$TOPIC/bb548544_en-us_VS_110_3_0_1_0_2%]<TSource, TKey> keySelector,
	[%$TOPIC/bb548544_en-us_VS_110_3_0_1_0_3%]<TSource, TElement> elementSelector,
	[%$TOPIC/bb548544_en-us_VS_110_3_0_1_0_4%]<TKey> comparer
generic<typename TSource, typename TKey, typename TElement>
static [%$TOPIC/bb548544_en-us_VS_110_3_0_2_0_1%]<TKey, TElement>^ ToLookup(
	[%$TOPIC/bb548544_en-us_VS_110_3_0_2_0_2%]<TSource>^ source, 
	[%$TOPIC/bb548544_en-us_VS_110_3_0_2_0_3%]<TSource, TKey>^ keySelector, 
	[%$TOPIC/bb548544_en-us_VS_110_3_0_2_0_4%]<TSource, TElement>^ elementSelector, 
	[%$TOPIC/bb548544_en-us_VS_110_3_0_2_0_5%]<TKey>^ comparer
static member ToLookup : 
        source:[%$TOPIC/bb548544_en-us_VS_110_3_0_3_0_0%]<'TSource> * 
        keySelector:[%$TOPIC/bb548544_en-us_VS_110_3_0_3_0_1%]<'TSource, 'TKey> * 
        elementSelector:[%$TOPIC/bb548544_en-us_VS_110_3_0_3_0_2%]<'TSource, 'TElement> * 
        comparer:[%$TOPIC/bb548544_en-us_VS_110_3_0_3_0_3%]<'TKey> -> [%$TOPIC/bb548544_en-us_VS_110_3_0_3_0_4%]<'TKey, 'TElement> 
JScript does not support generic types or methods.

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

The IEnumerableT to create a LookupTKey, TElement 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.

Type: System.Collections.GenericIEqualityComparerTKey

An IEqualityComparerT to compare keys.

Return Value

Type: System.LinqILookupTKey, TElement
A LookupTKey, TElement 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 .


The ToLookupTSource, TKey, TElement(IEnumerableTSource, FuncTSource, TKey, FuncTSource, TElement, IEqualityComparerTKey) method returns a LookupTKey, TElement, a one-to-many dictionary that maps keys to collections of values. A LookupTKey, TElement differs from a DictionaryTKey, TValue, which performs a one-to-one mapping of keys to single values.

If comparer is , the default equality comparer Default is used to compare keys.

Version Information

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

XNA Framework

Supported in: 3.0

Portable Class Library

Supported in: Portable Class Library

Supported in: Windows Phone 8.1

Supported in: Windows Phone Silverlight 8.1

Supported in: Windows Phone Silverlight 8