AttributeCollection.GetEnumerator Metodo

Definizione

Ottiene un enumeratore per la raccolta.Gets an enumerator for this collection.

public:
 virtual System::Collections::IEnumerator ^ GetEnumerator();
public:
 System::Collections::IEnumerator ^ GetEnumerator();
public System.Collections.IEnumerator GetEnumerator ();
abstract member GetEnumerator : unit -> System.Collections.IEnumerator
override this.GetEnumerator : unit -> System.Collections.IEnumerator
member this.GetEnumerator : unit -> System.Collections.IEnumerator
Public Function GetEnumerator () As IEnumerator

Restituisce

Enumeratore di tipo IEnumerator.An enumerator of type IEnumerator.

Implementazioni

Esempio

Nell'esempio di codice seguente viene ottenuto un enumeratore per gli attributi su button1.The following code example gets an enumerator for the attributes on button1. Usa l'enumeratore per stampare i nomi degli attributi nella raccolta.It uses the enumerator to print the names of the attributes in the collection. Si presuppone che button1 e textBox1 siano stati creati in un modulo.It assumes that button1 and textBox1 have been created on a form.

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() == true )
      {
         myAttribute = ie->Current;
         text->Append( myAttribute );
         text->Append( '\n' );
      }
      textBox1->Text = text->ToString();
   }
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;
    while(ie.MoveNext()==true) {
       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

Si applica a

Vedi anche