Partilhar via


ConfigurationSectionGroupCollection.GetEnumerator Método

Definição

Obtém um enumerador que pode iterar por meio do objeto 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

Retornos

Um IEnumerator que pode ser usado para iterar por meio do objeto ConfigurationSectionGroupCollection.

Exemplos

O exemplo de código a seguir mostra como usar o método 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

Aplica-se a

Confira também