StringEnumerator.Current プロパティ
アセンブリ: System (system.dll 内)



列挙子を作成した後や Reset を呼び出した後に、コレクションの最初の要素に列挙子を進めるためには、Current の値を読み取る前に MoveNext を呼び出す必要があります。それ以外の場合は、Current は未定義です。
MoveNext への最後の呼び出しで、コレクションの末尾を示す false が返された場合、Current は例外もスローします。
Current は列挙子の位置を移動しません。そのため、Current を連続して呼び出した場合、MoveNext または Reset が呼び出されるまでは同じオブジェクトが返されます。
コレクションが変更されない限り、列挙子は有効なままです。要素の追加、変更、削除などの変更がコレクションに対して実行されると、列挙子は回復不可能な無効状態になり、次に MoveNext または Reset を呼び出すと InvalidOperationException がスローされます。MoveNext と Current の間でコレクションを変更すると、列挙子が無効になっている場合でも、Current が設定先の要素を返します。

StringEnumerator のプロパティとメソッドのいくつかの例を次に示します。
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. */

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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からStringEnumerator.Current プロパティを検索する場合は、下記のリンクをクリックしてください。

- StringEnumerator.Current プロパティのページへのリンク