ConfigurationSectionCollection.GetEnumerator Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets an enumerator that can iterate through this ConfigurationSectionCollection object.
public:
override System::Collections::IEnumerator ^ GetEnumerator();
public override System.Collections.IEnumerator GetEnumerator ();
override this.GetEnumerator : unit -> System.Collections.IEnumerator
Public Iterator Overrides Function GetEnumerator () As IEnumerator
Public Overrides Function GetEnumerator () As IEnumerator
Returns
An IEnumerator that can be used to iterate through this ConfigurationSectionCollection object.
Examples
The following code example shows how to use GetEnumerator.
static void GetEnumerator()
{
try
{
System.Configuration.Configuration config =
ConfigurationManager.OpenExeConfiguration(
ConfigurationUserLevel.None);
ConfigurationSectionCollection sections =
config.Sections;
IEnumerator secEnum =
sections.GetEnumerator();
int i = 0;
while (secEnum.MoveNext())
{
string setionName = sections.GetKey(i);
Console.WriteLine(
"Section name: {0}", setionName);
i += 1;
}
}
catch (ConfigurationErrorsException err)
{
Console.WriteLine(err.ToString());
}
}
Shared Sub GetEnumerator()
Try
Dim config _
As System.Configuration.Configuration = _
ConfigurationManager.OpenExeConfiguration( _
ConfigurationUserLevel.None)
Dim sections _
As ConfigurationSectionCollection = _
config.Sections
Dim secEnum _
As IEnumerator = sections.GetEnumerator()
Dim i As Integer = 0
While secEnum.MoveNext()
Dim setionName _
As String = sections.GetKey(i)
Console.WriteLine( _
"Section name: {0}", setionName)
i += 1
End While
Catch err As ConfigurationErrorsException
Console.WriteLine(err.ToString())
End Try
End Sub
Applies to
See also
GitHub에서 Microsoft와 공동 작업
이 콘텐츠의 원본은 GitHub에서 찾을 수 있으며, 여기서 문제와 끌어오기 요청을 만들고 검토할 수도 있습니다. 자세한 내용은 참여자 가이드를 참조하세요.
.NET