IGrouping<TKey,TElement>.Key IGrouping<TKey,TElement>.Key IGrouping<TKey,TElement>.Key IGrouping<TKey,TElement>.Key Property

정의

IGrouping<TKey,TElement>의 키를 가져옵니다.Gets the key of the IGrouping<TKey,TElement>.

public:
 property TKey Key { TKey get(); };
public TKey Key { get; }
member this.Key : 'Key
Public ReadOnly Property Key As TKey

속성 값

TKey TKey TKey TKey

IGrouping<TKey,TElement>의 키입니다.The key of the IGrouping<TKey,TElement>.

예제

다음 예제에서는 사용 하는 방법에 설명 합니다 Key 속성에 각각 레이블을 IGrouping<TKey,TElement> 시퀀스의 개체 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. 합니다 GroupBy<TSource,TKey>(IEnumerable<TSource>, Func<TSource,TKey>) 메서드는 시퀀스를 가져오는 데 IGrouping<TKey,TElement> 개체입니다.The GroupBy<TSource,TKey>(IEnumerable<TSource>, Func<TSource,TKey>) method is used to obtain a sequence of IGrouping<TKey,TElement> objects. 합니다 foreach Visual C# 또는 For Each Visual Basic의 루프 다음 반복 각 IGrouping<TKey,TElement> 개체를 포함 하는 값의 수와 해당 키를 출력 합니다.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.

// Get a sequence of IGrouping objects.
IEnumerable<IGrouping<System.Reflection.MemberTypes, System.Reflection.MemberInfo>> memberQuery =
    typeof(String).GetMembers().
    GroupBy(member => member.MemberType);

// Output the key of each IGrouping object and the count of values.
foreach (IGrouping<System.Reflection.MemberTypes, System.Reflection.MemberInfo> group in memberQuery)
    Console.WriteLine("(Key) {0} (Member count) {1}", group.Key, group.Count());

// The output is similar to:
// (Key) Method (Member count) 113
// (Key) Constructor (Member count) 8
// (Key) Property (Member count) 2
// (Key) Field (Member count) 1

' Get a sequence of IGrouping objects.
Dim memberQuery As  _
IEnumerable(Of IGrouping(Of System.Reflection.MemberTypes, System.Reflection.MemberInfo)) = _
    Type.GetType("String").GetMembers(). _
    GroupBy(Function(ByVal member) member.MemberType)

' Output the key of each IGrouping object and the count of values.
For Each group As  _
IGrouping(Of System.Reflection.MemberTypes, System.Reflection.MemberInfo) In memberQuery
    MsgBox(String.Format("(Key) {0} (Member count) {1}", group.Key, group.Count()))
Next

' The output is similar to:
' (Key) Method (Member count) 113
' (Key) Constructor (Member count) 8
' (Key) Property (Member count) 2
' (Key) Field (Member count) 1

설명

키를 IGrouping<TKey,TElement> 에서 각 값에 공통적으로 적용 되는 특성을 나타내는 IGrouping<TKey,TElement>합니다.The key of an IGrouping<TKey,TElement> represents the attribute that is common to each value in the IGrouping<TKey,TElement>.

적용 대상