Comparteix a través de


ConfigurationSectionGroupCollection.GetEnumerator Método

Definición

Obtiene un enumerador que puede recorrer en iteración el 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

Devoluciones

Interfaz IEnumerator que se puede utilizar para recorrer en iteración el objeto ConfigurationSectionGroupCollection.

Ejemplos

En el ejemplo de código siguiente, se muestra cómo se utiliza el 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

Se aplica a

Consulte también