AttributeCollection.GetEnumerator Methode
Definitie
Belangrijk
Bepaalde informatie heeft betrekking op een voorlopige productversie die aanzienlijk kan worden gewijzigd voordat deze wordt uitgebracht. Microsoft biedt geen enkele expliciete of impliciete garanties met betrekking tot de informatie die hier wordt verstrekt.
Hiermee haalt u een enumerator op voor deze verzameling.
public:
System::Collections::IEnumerator ^ GetEnumerator();
public System.Collections.IEnumerator GetEnumerator();
member this.GetEnumerator : unit -> System.Collections.IEnumerator
Public Function GetEnumerator () As IEnumerator
Retouren
Een enumerator van het type IEnumerator.
Voorbeelden
In het volgende codevoorbeeld wordt een enumerator opgehaald voor de kenmerken op button1. De enumerator wordt gebruikt om de namen van de kenmerken in de verzameling af te drukken. Hierbij wordt ervan uitgegaan dat button1 en textBox1 zijn gemaakt op een formulier.
private:
void MyEnumerator()
{
// Creates a new collection and assigns it the attributes for button1.
AttributeCollection^ attributes;
attributes = TypeDescriptor::GetAttributes( button1 );
// Creates an enumerator for the collection.
System::Collections::IEnumerator^ ie = attributes->GetEnumerator();
// Prints the type of each attribute in the collection.
Object^ myAttribute;
System::Text::StringBuilder^ text = gcnew System::Text::StringBuilder;
while ( ie->MoveNext() )
{
myAttribute = ie->Current;
text->Append( myAttribute );
text->Append( '\n' );
}
textBox1->Text = text->ToString();
}
void MyEnumerator()
{
// Creates a new collection and assigns it the attributes for button1.
AttributeCollection attributes;
attributes = TypeDescriptor.GetAttributes(button1);
// Creates an enumerator for the collection.
System.Collections.IEnumerator ie = attributes.GetEnumerator();
// Prints the type of each attribute in the collection.
object myAttribute;
while (ie.MoveNext())
{
myAttribute = ie.Current;
textBox1.Text += myAttribute.ToString();
textBox1.Text += '\n';
}
}
Private Sub MyEnumerator
' Creates a new collection and assigns it the attributes for button1.
Dim attributes As AttributeCollection
attributes = TypeDescriptor.GetAttributes(button1)
' Creates an enumerator for the collection.
Dim ie As System.Collections.IEnumerator = attributes.GetEnumerator
' Prints the type of each attribute in the collection.
Dim myAttribute As Object
Do While ie.MoveNext
myAttribute = ie.Current
textBox1.Text = textBox1.Text & myAttribute.toString & ControlChars.crlf
Loop
End Sub