Freigeben über


StringEnumerator.Reset-Methode

Setzt den Enumerator auf seine anfängliche Position vor dem ersten Element in der Auflistung.

Namespace: System.Collections.Specialized
Assembly: System (in system.dll)

Syntax

'Declaration
Public Sub Reset
'Usage
Dim instance As StringEnumerator

instance.Reset
public void Reset ()
public:
void Reset ()
public void Reset ()
public function Reset ()

Ausnahmen

Ausnahmetyp Bedingung

InvalidOperationException

Die Auflistung wurde nach dem Erstellen des Enumerators geändert.

Hinweise

Reset setzt den Enumerator auf den Anfang der Auflistung, d. h. vor das erste Element. Nach Reset muss daher ein Aufruf von MoveNext erfolgen, um den Enumerator vor dem Lesen des Werts von Current auf das erste Element der Auflistung zu setzen.

Beispiel

Im folgenden Codebeispiel werden mehrere Eigenschaften und Methoden von StringEnumerator veranschaulicht.

Imports System
Imports System.Collections.Specialized

Public Class SamplesStringEnumerator

   Public Shared Sub Main()

      ' Creates and initializes a StringCollection.
      Dim myCol As New StringCollection()
      Dim myArr() As [String] = {"red", "orange", "yellow", "green", "blue", "indigo", "violet"}
      myCol.AddRange(myArr)

      ' Enumerates the elements in the StringCollection.
      Dim myEnumerator As StringEnumerator = myCol.GetEnumerator()
      While myEnumerator.MoveNext()
         Console.WriteLine("{0}", myEnumerator.Current)
      End While
      Console.WriteLine()

      ' Resets the enumerator and displays the first element again.
      myEnumerator.Reset()
      If myEnumerator.MoveNext() Then
         Console.WriteLine("The first element is {0}.", myEnumerator.Current)
      End If 

   End Sub 'Main

End Class 'SamplesStringEnumerator 


'This code produces the following output.
'
'red
'orange
'yellow
'green
'blue
'indigo
'violet
'
'The first element is red.
using System;
using System.Collections.Specialized;

public class SamplesStringEnumerator  {

   public static void Main()  {

      // Creates and initializes a StringCollection.
      StringCollection myCol = new StringCollection();
      String[] myArr = new String[] { "red", "orange", "yellow", "green", "blue", "indigo", "violet" };
      myCol.AddRange( myArr );

      // Enumerates the elements in the StringCollection.
      StringEnumerator myEnumerator = myCol.GetEnumerator();
      while ( myEnumerator.MoveNext() )
         Console.WriteLine( "{0}", myEnumerator.Current );
      Console.WriteLine();

      // Resets the enumerator and displays the first element again.
      myEnumerator.Reset();
      if ( myEnumerator.MoveNext() )
         Console.WriteLine( "The first element is {0}.", myEnumerator.Current );

   }

}

/*
This code produces the following output.

red
orange
yellow
green
blue
indigo
violet

The first element is red.

*/
#using <System.dll>

using namespace System;
using namespace System::Collections::Specialized;
int main()
{
   
   // Creates and initializes a StringCollection.
   StringCollection^ myCol = gcnew StringCollection;
   array<String^>^myArr = {"red","orange","yellow","green","blue","indigo","violet"};
   myCol->AddRange( myArr );
   
   // Enumerates the elements in the StringCollection.
   StringEnumerator^ myEnumerator = myCol->GetEnumerator();
   while ( myEnumerator->MoveNext() )
      Console::WriteLine( "{0}", myEnumerator->Current );

   Console::WriteLine();
   
   // Resets the enumerator and displays the first element again.
   myEnumerator->Reset();
   if ( myEnumerator->MoveNext() )
      Console::WriteLine( "The first element is {0}.", myEnumerator->Current );
}

/*
This code produces the following output.

red
orange
yellow
green
blue
indigo
violet

The first element is red.

*/
import System.* ;
import System.Collections.Specialized.* ;

public class SamplesStringEnumerator
{
    public static void main(String[] args)
    {
        // Creates and initializes a StringCollection.
        StringCollection myCol =  new StringCollection();
        String myArr[] = new String[]{"red", "orange", "yellow", "green", 
            "blue", "indigo", "violet"};
        myCol.AddRange(myArr);

        // Enumerates the elements in the StringCollection.
        StringEnumerator myEnumerator = myCol.GetEnumerator();
        while (myEnumerator.MoveNext()) {
            Console.WriteLine("{0}", myEnumerator.get_Current());
        }
        Console.WriteLine();

        // Resets the enumerator and displays the first element again.
        myEnumerator.Reset();
        if (myEnumerator.MoveNext()) {
            Console.WriteLine("The first element is {0}.", 
                myEnumerator.get_Current());
        }
    } //main 
} //SamplesStringEnumerator

/*
This code produces the following output.

red
orange
yellow
green
blue
indigo
violet

The first element is red.

*/

Plattformen

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

Siehe auch

Referenz

StringEnumerator-Klasse
StringEnumerator-Member
System.Collections.Specialized-Namespace
MoveNext
Current
IEnumerator.Reset