Export (0) Print
Expand All

ConfigurationSectionCollection.Item Property (String)

Gets the specified ConfigurationSection object.

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

public ConfigurationSection this[
	string name
] { get; }

Parameters

name
Type: System.String

The name of the ConfigurationSection object to be returned.

Property Value

Type: System.Configuration.ConfigurationSection
The ConfigurationSection object with the specified name.

This property gets the specified entry of the ConfigurationSectionCollection object.

In C#, this property is the indexer for the ConfigurationSectionCollection class.

The following code example shows how to use Item.

        static void GetItems()
        {

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

                ConfigurationSectionCollection sections =
                    config.Sections;


                ConfigurationSection section1 =
                    sections["runtime"];

                ConfigurationSection section2 =
                    sections[0];

                Console.WriteLine(
                     "Section1: {0}", section1.SectionInformation.Name);

                Console.WriteLine(
                    "Section2: {0}", section2.SectionInformation.Name);

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

.NET Framework

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

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft