다음을 통해 공유


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합니다. 열거자를 사용 하 여 컬렉션에 있는 특성의 이름을 인쇄 합니다. 가정 button1textBox1 폼에 만들었습니다.

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

적용 대상

추가 정보