共用方式為


ConfigurationSectionCollection.Get 方法

定義

取得這個 ConfigurationSection 物件中的 ConfigurationSectionCollection 物件。

多載

Get(Int32)

取得這個 ConfigurationSection 物件中包含之指定的 ConfigurationSectionCollection 物件。

Get(String)

取得這個 ConfigurationSection 物件中包含之指定的 ConfigurationSectionCollection 物件。

Get(Int32)

來源:
ConfigurationSectionCollection.cs
來源:
ConfigurationSectionCollection.cs
來源:
ConfigurationSectionCollection.cs

取得這個 ConfigurationSection 物件中包含之指定的 ConfigurationSectionCollection 物件。

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)

來源:
ConfigurationSectionCollection.cs
來源:
ConfigurationSectionCollection.cs
來源:
ConfigurationSectionCollection.cs

取得這個 ConfigurationSection 物件中包含之指定的 ConfigurationSectionCollection 物件。

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

另請參閱

適用於