StringEnumerator.MoveNext 메서드
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
열거자를 컬렉션의 다음 요소로 이동합니다.
public:
bool MoveNext();
public bool MoveNext ();
member this.MoveNext : unit -> bool
Public Function MoveNext () As Boolean
열거자가 다음 요소로 이동한 경우 true
이(가) 반환되고, 컬렉션의 끝을 지난 경우 false
이(가) 반환됩니다.
열거자가 만들어진 후에 컬렉션이 수정되었습니다.
다음 코드 예제에서는 의 여러 속성 및 메서드를 StringEnumerator보여 줍니다.
#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.
*/
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.
*/
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
End Class
'This code produces the following output.
'
'red
'orange
'yellow
'green
'blue
'indigo
'violet
'
'The first element is red.
열거자를 만들거나 가 호출된 후 Reset 열거자는 컬렉션의 첫 번째 요소 앞에 배치되고, 첫 번째 호출 MoveNext 은 컬렉션의 첫 번째 요소 위로 열거자를 이동합니다.
경우 MoveNext 열거자를 컬렉션의 끝 컬렉션의 마지막 요소 뒤에 배치 되는 전달 하 고 MoveNext 반환 false
합니다. 열거자가 있는 경우이 위치에 대 한 후속 호출은 MoveNext 반환할 수도 false
때까지 Reset 라고 합니다.
컬렉션이 변경되지 않고 그대로 유지되는 한 열거자는 유효한 상태로 유지됩니다. 변경에 추가 하는 등 컬렉션을 수정 하거나 요소를 삭제, 열거자가 복구할 유효 하지 않으며을 다음에 호출할 MoveNext 또는 Reset throw는 InvalidOperationException합니다. 컬렉션 사이 수정 된 경우 MoveNext 하 고 Current, Current 열거자가 이미 무효화 된 경우에로 설정 되어 있는 요소를 반환 합니다.
.NET 피드백
.NET은(는) 오픈 소스 프로젝트입니다. 다음 링크를 선택하여 피드백을 제공해 주세요.