AttributeCollection.GetEnumerator Method ()

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Gets an enumerator for this collection.

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

public IEnumerator GetEnumerator()

Return Value

Type: System.Collections.IEnumerator

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';
    }
 }

.NET Framework
Available since 1.1
Return to top
Show: