共用方式為


ConfigurationSectionGroupCollection.Get 方法

定義

從集合取得 ConfigurationSectionGroup 物件。

多載

Get(Int32)

取得集合中包含的指定之 ConfigurationSectionGroup 物件。

Get(String)

從集合取得指定的 ConfigurationSectionGroup 物件。

備註

這個方法是方法的 BaseGet 包裝函式。

Get(Int32)

來源:
ConfigurationSectionGroupCollection.cs
來源:
ConfigurationSectionGroupCollection.cs
來源:
ConfigurationSectionGroupCollection.cs

取得集合中包含的指定之 ConfigurationSectionGroup 物件。

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

參數

index
Int32

要傳回的 ConfigurationSectionGroup 物件索引。

傳回

位於指定索引處的 ConfigurationSectionGroup 物件。

備註

這個方法是方法的 BaseGet 包裝函式。

適用於

Get(String)

來源:
ConfigurationSectionGroupCollection.cs
來源:
ConfigurationSectionGroupCollection.cs
來源:
ConfigurationSectionGroupCollection.cs

從集合取得指定的 ConfigurationSectionGroup 物件。

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

參數

name
String

要傳回的 ConfigurationSectionGroup 物件名稱。

傳回

具有指定之名稱的 ConfigurationSectionGroup 物件。

例外狀況

name 為 null 或空字串 ("")。

範例

下列程式碼範例示範如何使用 Get 方法。

static void GetGroup()
{

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

        ConfigurationSectionGroup customGroup =
            config.SectionGroups.Get("CustomGroup");

        if (customGroup == null)
            Console.WriteLine(
                "Failed to load CustomSection.");
        else
        {
            // Display section information
            Console.WriteLine("Section group name:       {0}",
                customGroup.SectionGroupName);
            Console.WriteLine("Name:       {0}",
                customGroup.Name);
            Console.WriteLine("Type:   {0}",
                customGroup.Type);
        }
    }
    catch (ConfigurationErrorsException err)
    {
        Console.WriteLine(err.ToString());
    }
}
Shared Sub GetGroup()
   
   Try
         Dim config _
         As System.Configuration.Configuration = _
         ConfigurationManager.OpenExeConfiguration( _
         ConfigurationUserLevel.None)

         Dim groups _
         As ConfigurationSectionGroupCollection = _
         config.SectionGroups

         Dim customGroup _
         As ConfigurationSectionGroup = _
         groups.Get("CustomGroup")
      
      
      If customGroup Is Nothing Then
             Console.WriteLine( _
             "Failed to load CustomGroup.")
      Else
         ' Display section information
             Console.WriteLine("Name:       {0}", _
             customGroup.Name)
             Console.WriteLine("Type:   {0}", _
             customGroup.Type)
      End If
   
   
   Catch err As ConfigurationErrorsException
      Console.WriteLine(err.ToString())
   End Try
End Sub

備註

這個方法是方法的 BaseGet 包裝函式。

另請參閱

適用於