GetEnumerator Method
Collapse the table of content
Expand the table of content

ConfigurationSectionGroupCollection.GetEnumerator Method ()

 
Use BaseTrue

Gets an enumerator that can iterate through the ConfigurationSectionGroupCollection 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 the ConfigurationSectionGroupCollection object.

The following code example shows how to use the GetEnumerator method.

static void GetEnumerator()
{

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

        ConfigurationSectionGroupCollection groups =
            config.SectionGroups;

        IEnumerator groupEnum =
            groups.GetEnumerator();

        int i = 0;
        while (groupEnum.MoveNext())
        {
            string groupName = groups.GetKey(i);
            Console.WriteLine(
                "Group name: {0}", groupName);
            i += 1;
        }
    }
    catch (ConfigurationErrorsException err)
    {
        Console.WriteLine(err.ToString());
    }
}

.NET Framework
Available since 2.0
Return to top
Show:
© 2016 Microsoft