다음을 통해 공유


ConfigurationSectionGroupCollection.GetEnumerator 메서드

정의

ConfigurationSectionGroupCollection 개체를 반복할 수 있는 열거자를 가져옵니다.

public:
 override System::Collections::IEnumerator ^ GetEnumerator();
public override System.Collections.IEnumerator GetEnumerator ();
override this.GetEnumerator : unit -> System.Collections.IEnumerator
Public Overrides Function GetEnumerator () As IEnumerator
Public Iterator Overrides Function GetEnumerator () As IEnumerator

반환

IEnumerator 개체를 반복하는 데 사용할 수 있는 ConfigurationSectionGroupCollection입니다.

예제

다음 코드 예제에서는 GetEnumerator 메서드를 사용하는 방법을 보여 줍니다.

static void GetEnumerator()
{

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

        ConfigurationSectionGroupCollection groups =
            config.SectionGroups;

        IEnumerator groupEnum =
            groups.GetEnumerator();

        int i = 0;
        while (groupEnum.MoveNext())
        {
            string groupName = groups.GetKey(i);
            Console.WriteLine(
                "Group name: {0}", groupName);
            i += 1;
        }
    }
    catch (ConfigurationErrorsException err)
    {
        Console.WriteLine(err.ToString());
    }
}
Shared Sub GetEnumerator()
   
   Try
         Dim config _
         As System.Configuration.Configuration = _
         ConfigurationManager.OpenExeConfiguration( _
         ConfigurationUserLevel.None)

         Dim groups _
         As ConfigurationSectionGroupCollection = _
         config.SectionGroups

         Dim groupEnum As IEnumerator = _
         groups.GetEnumerator()
      
      Dim i As Integer = 0
      While groupEnum.MoveNext()
         Dim groupName As String = groups.GetKey(i)
         Console.WriteLine("Group name: {0}", groupName)
         i += 1
      End While

   Catch err As ConfigurationErrorsException
      Console.WriteLine(err.ToString())
   End Try
End Sub

적용 대상

추가 정보