PropertyDescriptorCollection.GetEnumerator Méthode

Définition

Retourne un énumérateur pour cette classe.

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

Retours

Énumérateur de type IEnumerator.

Implémente

Exemples

L’exemple de code suivant obtient un énumérateur pour les propriétés sur button1. Il utilise l’énumérateur pour imprimer les noms des propriétés de la collection. Il nécessite que button1 et textBox1 ont été instanciés sur un formulaire.

private:
   void MyEnumerator()
   {
      // Creates a new collection and assigns it the properties for button1.
      PropertyDescriptorCollection^ properties = TypeDescriptor::GetProperties( button1 );
      
      // Creates an enumerator.
      IEnumerator^ ie = properties->GetEnumerator();
      
      // Prints the name of each property in the collection.
      Object^ myProperty;
      while ( ie->MoveNext() == true )
      {
         myProperty = ie->Current;
         textBox1->Text = textBox1->Text + myProperty + "\n";
      }
   }
private void MyEnumerator() {
   // Creates a new collection and assigns it the properties for button1.
   PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(button1);

   // Creates an enumerator.
   IEnumerator ie = properties.GetEnumerator();

   // Prints the name of each property in the collection.
   Object myProperty;
   while(ie.MoveNext()==true) {
      myProperty = ie.Current;
      textBox1.Text += myProperty.ToString() + '\n';
   }
}
Private Sub MyEnumerator()
    ' Creates a new collection and assigns it the properties for button1.
    Dim properties As PropertyDescriptorCollection = _
       TypeDescriptor.GetProperties(button1)
       
    ' Creates an enumerator.
    Dim ie As IEnumerator = properties.GetEnumerator()
       
    ' Prints the name of each property in the collection.
    Dim myProperty As Object
    While ie.MoveNext() = True
        myProperty = ie.Current
        textBox1.Text &= myProperty.ToString() & ControlChars.Cr
    End While
End Sub

S’applique à

Voir aussi