共用方式為


Lookup<TKey,TElement>.GetEnumerator 方法

定義

傳回會逐一查看 Lookup<TKey,TElement> 的泛型列舉值。

public:
 virtual System::Collections::Generic::IEnumerator<System::Linq::IGrouping<TKey, TElement> ^> ^ GetEnumerator();
public System.Collections.Generic.IEnumerator<System.Linq.IGrouping<TKey,TElement>> GetEnumerator ();
abstract member GetEnumerator : unit -> System.Collections.Generic.IEnumerator<System.Linq.IGrouping<'Key, 'Element>>
override this.GetEnumerator : unit -> System.Collections.Generic.IEnumerator<System.Linq.IGrouping<'Key, 'Element>>
Public Function GetEnumerator () As IEnumerator(Of IGrouping(Of TKey, TElement))
Public Iterator Overridable NotOverridable Function GetEnumerator () As IEnumerator(Of IGrouping(Of TKey, TElement))

傳回

IEnumerator<IGrouping<TKey,TElement>>

Lookup<TKey,TElement> 的列舉程式。

實作

範例

下列範例示範如何使用 GetEnumerator 來逐一查看 的 Lookup<TKey,TElement>索引鍵和值。 此程式代碼範例是針對 類別提供的較大範例的 Lookup<TKey,TElement> 一部分。

// Iterate through each IGrouping in the Lookup and output the contents.
foreach (IGrouping<char, string> packageGroup in lookup)
{
    // Print the key value of the IGrouping.
    Console.WriteLine(packageGroup.Key);
    // Iterate through each value in the IGrouping and print its value.
    foreach (string str in packageGroup)
        Console.WriteLine("    {0}", str);
}
Dim output As New System.Text.StringBuilder
' Iterate through each IGrouping in the Lookup and output the contents.
For Each packageGroup As IGrouping(Of Char, String) In lookup
    ' Print the key value of the IGrouping.
    output.AppendLine(packageGroup.Key)
    ' Iterate through each value in the IGrouping and print its value.
    For Each str As String In packageGroup
        output.AppendLine(String.Format("    {0}", str))
    Next
Next

' Display the output.
MsgBox(output.ToString())

適用於