Lookup<TKey,TElement>.GetEnumerator Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Returns a generic enumerator that iterates through the 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))
Returns
IEnumerator<IGrouping<TKey,TElement>>
An enumerator for the Lookup<TKey,TElement>.
Implements
Examples
The following example demonstrates how to use GetEnumerator to iterate through the keys and values of a Lookup<TKey,TElement>. This code example is part of a larger example provided for the Lookup<TKey,TElement> class.
// 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())
Applies to
Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.