Export (0) Print
Expand All

IGrouping<TKey, TElement>::Key Property

Gets the key of the IGrouping<TKey, TElement>.

Namespace:  System.Linq
Assemblies:   System.Linq (in System.Linq.dll)
  System.Core (in System.Core.dll)

property TKey Key {
	TKey get ();
}

Property Value

Type: TKey
The key of the IGrouping<TKey, TElement>.

The key of an IGrouping<TKey, TElement> represents the attribute that is common to each value in the IGrouping<TKey, TElement>.

The following example demonstrates how to use the Key property to label each IGrouping<TKey, TElement> object in a sequence of IGrouping<TKey, TElement> objects. The GroupBy<TSource, TKey>(IEnumerable<TSource>, Func<TSource, TKey>) method is used to obtain a sequence of IGrouping<TKey, TElement> objects. The foreach in Visual C# or For Each in Visual Basic loop then iterates through each IGrouping<TKey, TElement> object, outputting its key and the number of values it contains.

No code example is currently available or this language may not be supported.

.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
Show:
© 2015 Microsoft