ConfigurationSectionCollection.Item[] 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得指定的 ConfigurationSection 物件。
多載
Item[Int32] |
取得指定的 ConfigurationSection 物件。 |
Item[String] |
取得指定的 ConfigurationSection 物件。 |
Item[Int32]
取得指定的 ConfigurationSection 物件。
public:
property System::Configuration::ConfigurationSection ^ default[int] { System::Configuration::ConfigurationSection ^ get(int index); };
public System.Configuration.ConfigurationSection this[int index] { get; }
member this.Item(int) : System.Configuration.ConfigurationSection
Default Public ReadOnly Property Item(index As Integer) As ConfigurationSection
參數
- index
- Int32
要傳回的 ConfigurationSection 物件索引。
屬性值
位於指定索引處的 ConfigurationSection 物件。
範例
下列程式碼範例示範如何使用 Item[]。
static void GetItems()
{
try
{
System.Configuration.Configuration config =
ConfigurationManager.OpenExeConfiguration(
ConfigurationUserLevel.None);
ConfigurationSectionCollection sections =
config.Sections;
ConfigurationSection section1 =
sections["runtime"];
ConfigurationSection section2 =
sections[0];
Console.WriteLine(
"Section1: {0}", section1.SectionInformation.Name);
Console.WriteLine(
"Section2: {0}", section2.SectionInformation.Name);
}
catch (ConfigurationErrorsException err)
{
Console.WriteLine(err.ToString());
}
}
Shared Sub GetItems()
Try
Dim config _
As System.Configuration.Configuration = _
ConfigurationManager.OpenExeConfiguration( _
ConfigurationUserLevel.None)
Dim sections _
As ConfigurationSectionCollection = _
config.Sections
Dim section1 As ConfigurationSection = _
sections.Item("runtime")
Dim section2 As ConfigurationSection = _
sections.Item(0)
Console.WriteLine("Section1: {0}", _
section1.SectionInformation.Name)
Console.WriteLine("Section2: {0}", _
section2.SectionInformation.Name)
Catch err As ConfigurationErrorsException
Console.WriteLine(err.ToString())
End Try
End Sub
備註
這個屬性會取得 物件的指定專案 ConfigurationSectionCollection 。
在 C# 中,這個屬性是 ConfigurationSectionCollection 類別的索引子。
另請參閱
適用於
Item[String]
取得指定的 ConfigurationSection 物件。
public:
property System::Configuration::ConfigurationSection ^ default[System::String ^] { System::Configuration::ConfigurationSection ^ get(System::String ^ name); };
public System.Configuration.ConfigurationSection this[string name] { get; }
member this.Item(string) : System.Configuration.ConfigurationSection
Default Public ReadOnly Property Item(name As String) As ConfigurationSection
參數
- name
- String
要傳回的 ConfigurationSection 物件名稱。
屬性值
具有指定之名稱的 ConfigurationSection 物件。
範例
下列程式碼範例示範如何使用 Item[]。
static void GetItems()
{
try
{
System.Configuration.Configuration config =
ConfigurationManager.OpenExeConfiguration(
ConfigurationUserLevel.None);
ConfigurationSectionCollection sections =
config.Sections;
ConfigurationSection section1 =
sections["runtime"];
ConfigurationSection section2 =
sections[0];
Console.WriteLine(
"Section1: {0}", section1.SectionInformation.Name);
Console.WriteLine(
"Section2: {0}", section2.SectionInformation.Name);
}
catch (ConfigurationErrorsException err)
{
Console.WriteLine(err.ToString());
}
}
Shared Sub GetItems()
Try
Dim config _
As System.Configuration.Configuration = _
ConfigurationManager.OpenExeConfiguration( _
ConfigurationUserLevel.None)
Dim sections _
As ConfigurationSectionCollection = _
config.Sections
Dim section1 As ConfigurationSection = _
sections.Item("runtime")
Dim section2 As ConfigurationSection = _
sections.Item(0)
Console.WriteLine("Section1: {0}", _
section1.SectionInformation.Name)
Console.WriteLine("Section2: {0}", _
section2.SectionInformation.Name)
Catch err As ConfigurationErrorsException
Console.WriteLine(err.ToString())
End Try
End Sub
備註
這個屬性會取得 物件的指定專案 ConfigurationSectionCollection 。
在 C# 中,這個屬性是 ConfigurationSectionCollection 類別的索引子。