Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Keys Property
Collapse the table of content
Expand the table of content

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

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Show:
© 2015 Microsoft