共用方式為


AttributeCollection.GetEnumerator 方法

定義

取得這個集合的列舉程式。

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

傳回

IEnumerator 型別的列舉程式。

實作

範例

下列程式代碼範例會取得 上 button1屬性的列舉值。 它會使用列舉值來列印集合中屬性的名稱。 它假設 button1 已在表單上建立 和 textBox1

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

適用於

另請參閱