.NET Framework Class Library
EnumerableGroupByTSource, TKey, TResult Method (IEnumerableTSource, FuncTSource, TKey, FuncTKey, IEnumerableTSource, TResult, IEqualityComparerTKey)

Groups the elements of a sequence according to a specified key selector function and creates a result value from each group and its key. The keys are compared by using a specified comparer.

Namespace:   System.Linq
Assemblies:   System.Linq (in System.Linq.dll)
  System.Core (in System.Core.dll)
<[%$TOPIC/bb549140_en-us_VS_110_1_0_0_0_0%]> _
Public Shared Function GroupBy(Of TSource, TKey, TResult) ( _
	source As [%$TOPIC/bb549140_en-us_VS_110_1_0_0_0_1%](Of TSource), _
	keySelector As [%$TOPIC/bb549140_en-us_VS_110_1_0_0_0_2%](Of TSource, TKey), _
	resultSelector As [%$TOPIC/bb549140_en-us_VS_110_1_0_0_0_3%](Of TKey, [%$TOPIC/bb549140_en-us_VS_110_1_0_0_0_4%](Of TSource), TResult), _
	comparer As [%$TOPIC/bb549140_en-us_VS_110_1_0_0_0_5%](Of TKey) _
) As [%$TOPIC/bb549140_en-us_VS_110_1_0_0_0_6%](Of TResult)
public static [%$TOPIC/bb549140_en-us_VS_110_1_0_1_0_0%]<TResult> GroupBy<TSource, TKey, TResult>(
	this [%$TOPIC/bb549140_en-us_VS_110_1_0_1_0_1%]<TSource> source,
	[%$TOPIC/bb549140_en-us_VS_110_1_0_1_0_2%]<TSource, TKey> keySelector,
	[%$TOPIC/bb549140_en-us_VS_110_1_0_1_0_3%]<TKey, [%$TOPIC/bb549140_en-us_VS_110_1_0_1_0_4%]<TSource>, TResult> resultSelector,
	[%$TOPIC/bb549140_en-us_VS_110_1_0_1_0_5%]<TKey> comparer
generic<typename TSource, typename TKey, typename TResult>
static [%$TOPIC/bb549140_en-us_VS_110_1_0_2_0_1%]<TResult>^ GroupBy(
	[%$TOPIC/bb549140_en-us_VS_110_1_0_2_0_2%]<TSource>^ source, 
	[%$TOPIC/bb549140_en-us_VS_110_1_0_2_0_3%]<TSource, TKey>^ keySelector, 
	[%$TOPIC/bb549140_en-us_VS_110_1_0_2_0_4%]<TKey, [%$TOPIC/bb549140_en-us_VS_110_1_0_2_0_5%]<TSource>^, TResult>^ resultSelector, 
	[%$TOPIC/bb549140_en-us_VS_110_1_0_2_0_6%]<TKey>^ comparer
static member GroupBy : 
        source:[%$TOPIC/bb549140_en-us_VS_110_1_0_3_0_0%]<'TSource> * 
        keySelector:[%$TOPIC/bb549140_en-us_VS_110_1_0_3_0_1%]<'TSource, 'TKey> * 
        resultSelector:[%$TOPIC/bb549140_en-us_VS_110_1_0_3_0_2%]<'TKey, [%$TOPIC/bb549140_en-us_VS_110_1_0_3_0_3%]<'TSource>, 'TResult> * 
        comparer:[%$TOPIC/bb549140_en-us_VS_110_1_0_3_0_4%]<'TKey> -> [%$TOPIC/bb549140_en-us_VS_110_1_0_3_0_5%]<'TResult> 
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 result value returned by resultSelector.


Type: System.Collections.GenericIEnumerableTSource

An IEnumerableT whose elements to group.

Type: SystemFuncTSource, TKey

A function to extract the key for each element.

Type: SystemFuncTKey, IEnumerableTSource, TResult

A function to create a result value from each group.

Type: System.Collections.GenericIEqualityComparerTKey

An IEqualityComparerT to compare keys with.

Return Value

Type: System.Collections.GenericIEnumerableTResult
A collection of elements of type TResult where each element represents a projection over a group and its key.

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).
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

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone Silverlight 8.1, Windows Phone Silverlight 8

Portable Class Library

Supported in: Portable Class Library