Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
Item Property
 Item Property (String)
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
ConfigurationSectionCollection..::.Item Property (String)

Gets the specified ConfigurationSection object.

Namespace:  System.Configuration
Assembly:  System.Configuration (in System.Configuration.dll)
Visual Basic (Declaration)
Public ReadOnly Property Item ( _
    name As String _
) As ConfigurationSection
Visual Basic (Usage)
Dim instance As ConfigurationSectionCollection
Dim name As String
Dim value As ConfigurationSection

value = instance.Item(name)
C#
public ConfigurationSection this[
    string name
] { get; }
Visual C++
public:
property ConfigurationSection^ Item[String^ name] {
    ConfigurationSection^ get (String^ name);
}
JScript
JScript does not support indexed properties.

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.

Visual Basic
Shared Sub GetItems()

    Try
        Dim config _
        As System.Configuration.Configuration = _
        ConfigurationManager.OpenExeConfiguration( _
        ConfigurationUserLevel.None)

        Dim sections _
        As ConfigurationSectionCollection = _
        config.Sections


        Dim section1 As ConfigurationSection = _
        sections.Item("runtime")

        Dim section2 As ConfigurationSection = _
        sections.Item(0)

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

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

    Catch err As ConfigurationErrorsException
        Console.WriteLine(err.ToString())
    End Try
End Sub 'GetItems


C#
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());
    }
}

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

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

.NET Framework

Supported in: 3.5, 3.0, 2.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker