ConfigurationSectionGroupCollection.Item[] 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置此 ConfigurationSectionGroup 对象中包含的 ConfigurationSectionGroupCollection 对象。
重载
Item[Int32] |
获取 ConfigurationSectionGroup 对象,该对象的索引从集合中指定。 |
Item[String] |
获取 ConfigurationSectionGroup 对象,该对象的名称从集合中指定。 |
示例
以下示例演示如何使用 Item[] 属性循环访问 ConfigurationSectionGroupCollection。
static void ShowSectionGroupCollectionInfo(ConfigurationSectionGroupCollection mySectionGroupCollection)
{
foreach (String mySectionGroupName in mySectionGroupCollection.Keys)
{
ConfigurationSectionGroup mySectionGroup =
(ConfigurationSectionGroup)mySectionGroupCollection[mySectionGroupName];
ShowSectionGroupInfo(mySectionGroup);
}
}
Shared Sub ShowSectionGroupCollectionInfo(mySectionGroupCollection As System.Configuration.ConfigurationSectionGroupCollection)
Dim mySectionGroupName As String
For Each mySectionGroupName In mySectionGroupCollection.Keys
Dim mySectionGroup As System.Configuration.ConfigurationSectionGroup = CType(mySectionGroupCollection(mySectionGroupName), System.Configuration.ConfigurationSectionGroup)
ShowSectionGroupInfo(mySectionGroup)
Next mySectionGroupName
End Sub
Item[Int32]
获取 ConfigurationSectionGroup 对象,该对象的索引从集合中指定。
public:
property System::Configuration::ConfigurationSectionGroup ^ default[int] { System::Configuration::ConfigurationSectionGroup ^ get(int index); };
public System.Configuration.ConfigurationSectionGroup this[int index] { get; }
member this.Item(int) : System.Configuration.ConfigurationSectionGroup
Default Public ReadOnly Property Item(index As Integer) As ConfigurationSectionGroup
参数
- index
- Int32
要返回的 ConfigurationSectionGroup 对象的索引。
属性值
指定索引处的 ConfigurationSectionGroup 对象。
在 C# 中,此属性是 ConfigurationSectionCollection 类的索引器。
适用于
Item[String]
获取 ConfigurationSectionGroup 对象,该对象的名称从集合中指定。
public:
property System::Configuration::ConfigurationSectionGroup ^ default[System::String ^] { System::Configuration::ConfigurationSectionGroup ^ get(System::String ^ name); };
public System.Configuration.ConfigurationSectionGroup this[string name] { get; }
member this.Item(string) : System.Configuration.ConfigurationSectionGroup
Default Public ReadOnly Property Item(name As String) As ConfigurationSectionGroup
参数
- name
- String
要返回的 ConfigurationSectionGroup 对象名称。
属性值
具有指定名称的 ConfigurationSectionGroup 对象。
在 C# 中,此属性是 ConfigurationSectionCollection 类的索引器。
示例
下面的代码示例说明如何使用 Item[] 属性。
static void GetItems()
{
try
{
System.Configuration.Configuration config =
ConfigurationManager.OpenExeConfiguration(
ConfigurationUserLevel.None);
ConfigurationSectionGroupCollection groups =
config.SectionGroups;
ConfigurationSectionGroup group1 =
groups.Get("system.net");
ConfigurationSectionGroup group2 =
groups.Get("system.web");
Console.WriteLine(
"Group1: {0}", group1.Name);
Console.WriteLine(
"Group2: {0}", group2.Name);
}
catch (ConfigurationErrorsException err)
{
Console.WriteLine(err.ToString());
}
}
Shared Sub GetItems()
Try
Dim config _
As System.Configuration.Configuration = _
ConfigurationManager.OpenExeConfiguration( _
ConfigurationUserLevel.None)
Dim groups _
As ConfigurationSectionGroupCollection = _
config.SectionGroups
Dim group1 As ConfigurationSectionGroup = _
groups.Get("system.net")
Dim group2 As ConfigurationSectionGroup = _
groups.Get("system.web")
Console.WriteLine("Group1: {0}", group1.Name)
Console.WriteLine("Group2: {0}", group2.Name)
Catch err As ConfigurationErrorsException
Console.WriteLine(err.ToString())
End Try
End Sub