ConfigurationSectionCollection.Get 方法

定义

获取此 ConfigurationSectionCollection 对象中的 ConfigurationSection 对象。

重载

Get(Int32)

获取此 ConfigurationSectionCollection 对象中包含的指定 ConfigurationSection 对象。

Get(String)

获取此 ConfigurationSectionCollection 对象中包含的指定 ConfigurationSection 对象。

Get(Int32)

Source:
ConfigurationSectionCollection.cs
Source:
ConfigurationSectionCollection.cs
Source:
ConfigurationSectionCollection.cs

获取此 ConfigurationSectionCollection 对象中包含的指定 ConfigurationSection 对象。

public:
 System::Configuration::ConfigurationSection ^ Get(int index);
public System.Configuration.ConfigurationSection Get (int index);
member this.Get : int -> System.Configuration.ConfigurationSection
Public Function Get (index As Integer) As ConfigurationSection

参数

index
Int32

要返回的 ConfigurationSection 对象的索引。

返回

指定索引处的 ConfigurationSection 对象。

适用于

Get(String)

Source:
ConfigurationSectionCollection.cs
Source:
ConfigurationSectionCollection.cs
Source:
ConfigurationSectionCollection.cs

获取此 ConfigurationSectionCollection 对象中包含的指定 ConfigurationSection 对象。

public:
 System::Configuration::ConfigurationSection ^ Get(System::String ^ name);
public System.Configuration.ConfigurationSection Get (string name);
member this.Get : string -> System.Configuration.ConfigurationSection
Public Function Get (name As String) As ConfigurationSection

参数

name
String

要返回的 ConfigurationSection 对象名称。

返回

具有指定名称的 ConfigurationSection 对象。

例外

name 为 null 或为空字符串 ("")。

示例

下面的代码示例说明如何使用 Get

static void GetSection()
{

    try
    {
        CustomSection customSection =
            ConfigurationManager.GetSection(
            "CustomSection") as CustomSection;

        if (customSection == null)
            Console.WriteLine(
                "Failed to load CustomSection.");
        else
        {
            // Display section information
            Console.WriteLine("Defaults:");
            Console.WriteLine("File Name:       {0}",
                customSection.FileName);
            Console.WriteLine("Max Users:       {0}",
                customSection.MaxUsers);
            Console.WriteLine("Max Idle Time:   {0}",
                customSection.MaxIdleTime);
        }
    }
    catch (ConfigurationErrorsException err)
    {
        Console.WriteLine(err.ToString());
    }
}
Shared Sub GetSection()

    Try
        Dim customSection _
        As CustomSection = _
        ConfigurationManager.GetSection( _
        "CustomSection")

        If customSection Is Nothing Then
            Console.WriteLine("Failed to load CustomSection.")
        Else
            ' Display section information
            Console.WriteLine("Defaults:")
            Console.WriteLine("File Name:       {0}", _
            customSection.FileName)
            Console.WriteLine("Max Users:       {0}", _
            customSection.MaxUsers)
            Console.WriteLine("Max Idle Time:   {0}", _
            customSection.MaxIdleTime)
        End If


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

另请参阅

适用于