StringEnumerator.Current プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > StringEnumerator.Current プロパティの意味・解説 

StringEnumerator.Current プロパティ

コレクション内の現在の要素取得します

名前空間: System.Collections.Specialized
アセンブリ: System (system.dll 内)
構文構文

例外例外
例外種類条件

InvalidOperationException

列挙子が、コレクション最初要素の前、または最後要素の後に位置してます。

解説解説

列挙子を作成した後や Reset呼び出した後に、コレクション最初要素列挙子を進めるためには、Current の値を読み取る前に MoveNext を呼び出す必要がありますそれ以外場合は、Current未定義です。

MoveNext への最後呼び出しで、コレクション末尾を示す false返され場合Current例外スローます。

Current列挙子の位置移動しません。そのため、Current連続して呼び出した場合MoveNext または Reset呼び出されるまでは同じオブジェクト返されます。

コレクション変更されない限り列挙子は有効なままです。要素追加変更削除などの変更コレクションに対して実行されると、列挙子は回復不可能な無効状態になり、次に MoveNext または Reset呼び出すと InvalidOperationExceptionスローさます。MoveNextCurrent の間でコレクション変更すると、列挙子が無効になっている場合でも、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.

*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
StringEnumerator クラス
StringEnumerator メンバ
System.Collections.Specialized 名前空間
MoveNext
Reset
IEnumerator.Current プロパティ


このページでは「.NET Framework クラス ライブラリ リファレンス」からStringEnumerator.Current プロパティを検索した結果を表示しています。
Weblioに収録されているすべての辞書からStringEnumerator.Current プロパティを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からStringEnumerator.Current プロパティ を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

StringEnumerator.Current プロパティのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



StringEnumerator.Current プロパティのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS