ConfigurationSectionCollection.GetEnumerator Method ()

 
Use BaseTrue

Gets an enumerator that can iterate through this ConfigurationSectionCollection object.

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

public override IEnumerator GetEnumerator()

Return Value

Type: System.Collections.IEnumerator

An IEnumerator that can be used to iterate through this ConfigurationSectionCollection object.

The following code example shows how to use GetEnumerator.

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());
    }
}

.NET Framework
Available since 2.0
Return to top
Show: