ConfigurationSectionCollection.Item Property (Int32)

 

Gets the specified ConfigurationSection object.

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

public ConfigurationSection this[
	int index
] { get; }

Parameters

index
Type: System.Int32

The index of the ConfigurationSection object to be returned.

Property Value

Type: System.Configuration.ConfigurationSection

The ConfigurationSection object at the specified index.

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
Available since 2.0
Return to top
Show: