ConfigurationSectionGroupCollection.Get 方法

定义

从集合中获取一个 ConfigurationSectionGroup 对象。

重载

Get(Int32)

获取包含在集合中的指定 ConfigurationSectionGroup 对象。

Get(String)

从集合中获取指定的 ConfigurationSectionGroup 对象。

注解

此方法是 方法的 BaseGet 包装器。

Get(Int32)

Source:
ConfigurationSectionGroupCollection.cs
Source:
ConfigurationSectionGroupCollection.cs
Source:
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)

Source:
ConfigurationSectionGroupCollection.cs
Source:
ConfigurationSectionGroupCollection.cs
Source:
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 包装器。

另请参阅

适用于