ConfigurationSectionCollection.Keys Property

 

Gets the keys to all ConfigurationSection objects contained in this ConfigurationSectionCollection object.

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

public override NameObjectCollectionBase.KeysCollection Keys { get; }

Property Value

Type: System.Collections.Specialized.NameObjectCollectionBase.KeysCollection

A NameObjectCollectionBase.KeysCollection object that contains the keys of all sections in this collection.

The following example shows how to use the Keys property.

static void GetKeys()
{

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

        ConfigurationSectionCollection sections =
            config.Sections;


        foreach (string key in sections.Keys)
        {


            Console.WriteLine(
             "Key value: {0}", key);
        }


    }
    catch (ConfigurationErrorsException err)
    {
        Console.WriteLine(err.ToString());
    }
}

.NET Framework
Available since 2.0
Return to top
Show: