Aracılığıyla paylaş


StringEnumerator.Current Özellik

Tanım

Koleksiyondaki geçerli öğeyi alır.

public:
 property System::String ^ Current { System::String ^ get(); };
public string Current { get; }
public string? Current { get; }
member this.Current : string
Public ReadOnly Property Current As String

Özellik Değeri

Koleksiyondaki geçerli öğe.

Özel durumlar

Numaralandırıcı, koleksiyonun ilk öğesinden önce veya son öğeden sonra konumlandırılır.

Örnekler

Aşağıdaki kod örneği, özelliklerinin ve yöntemlerinin birkaçını StringEnumeratorgösterir.

#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.

Açıklamalar

Bir numaralandırıcı oluşturulduktan veya çağrıldıktan Reset sonra, MoveNext değerini Currentokumadan önce numaralandırıcıyı koleksiyonun ilk öğesine ilerletmek için çağrılmalıdır; aksi takdirde tanımsızdır Current .

Currentayrıca, döndürülen falseson çağrısı MoveNext koleksiyonun sonunu gösterirse bir özel durum oluşturur.

Currentnumaralandırıcının konumunu taşımaz ve veya Reset çağrılana kadar MoveNext aynı nesneyi döndürmek için Current ardışık çağrılar yapar.

Bir numaralandırıcı, koleksiyon değişmeden kaldığı sürece geçerli kalır. Koleksiyonda öğe ekleme, değiştirme veya silme gibi değişiklikler yapılırsa, numaralandırıcı geri alınamaz şekilde geçersiz kılınmış olur ve bir sonraki çağrısı MoveNext veya Reset oluşturur InvalidOperationException. Koleksiyon ile CurrentCurrent arasında MoveNext değiştirilirse, numaralandırıcı zaten geçersiz olsa bile, ayarlandığı öğeyi döndürür.

Şunlara uygulanır

Ayrıca bkz.