AttributeCollection.GetEnumerator Method

Gets an enumerator for this collection.

Namespace: System.ComponentModel
Assembly: System (in system.dll)

public IEnumerator GetEnumerator ()
public IEnumerator GetEnumerator ()
public function GetEnumerator () : IEnumerator
Not applicable.

Return Value

An enumerator of type IEnumerator.

The following code example gets an enumerator for the attributes on button1. It uses the enumerator to print the names of the attributes in the collection. 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;
    while(ie.MoveNext()==true) {
       myAttribute = ie.Current;
       textBox1.Text += myAttribute.ToString();
       textBox1.Text += '\n';
    }
 }


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.get_Current();
        textBox1.set_Text(textBox1.get_Text() + myAttribute.ToString());
        textBox1.set_Text(textBox1.get_Text() + '\n');
    }
} //MyEnumerator

private function MyEnumerator() {
    // Creates a new collection and assigns it the attributes for button1.
    var attributes : AttributeCollection;
    attributes = TypeDescriptor.GetAttributes(button1);
 
    // Creates an enumerator for the collection.
    var ie : System.Collections.IEnumerator  = attributes.GetEnumerator();
 
    // Prints the type of each attribute in the collection.
    var myAttribute;
    while(ie.MoveNext()==true) {
       myAttribute = ie.Current;
       textBox1.Text += myAttribute.ToString();
       textBox1.Text += '\n';
    }
 }


Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0
Show: