ConfigurationSectionCollection.GetEnumerator Methode

Definition

Ruft einen Enumerator ab, der dieses ConfigurationSectionCollection-Objekt durchlaufen kann.

public:
 override System::Collections::IEnumerator ^ GetEnumerator();
public override System.Collections.IEnumerator GetEnumerator ();
override this.GetEnumerator : unit -> System.Collections.IEnumerator
Public Overrides Function GetEnumerator () As IEnumerator
Public Iterator Overrides Function GetEnumerator () As IEnumerator

Gibt zurück

Ein IEnumerator, der zum Durchlaufen dieses ConfigurationSectionCollection-Objekts verwendet werden kann.

Beispiele

Im folgenden Codebeispiel wird die Verwendung von GetEnumerator veranschaulicht.

static void GetEnumerator()
{

    try
    {
        System.Configuration.Configuration config =
        ConfigurationManager.OpenExeConfiguration(
        ConfigurationUserLevel.None);

        ConfigurationSectionCollection sections =
            config.Sections;

        IEnumerator secEnum =
            sections.GetEnumerator();

        int i = 0;
        while (secEnum.MoveNext())
        {
            string setionName = sections.GetKey(i);
            Console.WriteLine(
                "Section name: {0}", setionName);
            i += 1;
        }
    }
    catch (ConfigurationErrorsException err)
    {
        Console.WriteLine(err.ToString());
    }
}
Shared Sub GetEnumerator()

    Try
        Dim config _
        As System.Configuration.Configuration = _
        ConfigurationManager.OpenExeConfiguration( _
        ConfigurationUserLevel.None)

        Dim sections _
        As ConfigurationSectionCollection = _
        config.Sections

        Dim secEnum _
        As IEnumerator = sections.GetEnumerator()

        Dim i As Integer = 0
        While secEnum.MoveNext()
            Dim setionName _
            As String = sections.GetKey(i)
            Console.WriteLine( _
            "Section name: {0}", setionName)
            i += 1
        End While
    Catch err As ConfigurationErrorsException
        Console.WriteLine(err.ToString())
    End Try
End Sub

Gilt für:

Weitere Informationen