Sdílet prostřednictvím


ForEachEnumeratorInfosEnumerator.Current Property

Definition

Returns the current ForEachEnumeratorInfo object from the collection.

public:
 property Microsoft::SqlServer::Dts::Runtime::ForEachEnumeratorInfo ^ Current { Microsoft::SqlServer::Dts::Runtime::ForEachEnumeratorInfo ^ get(); };
public Microsoft.SqlServer.Dts.Runtime.ForEachEnumeratorInfo Current { get; }
member this.Current : Microsoft.SqlServer.Dts.Runtime.ForEachEnumeratorInfo
Public ReadOnly Property Current As ForEachEnumeratorInfo

Property Value

The current ForEachEnumeratorInfo object in the collection.

Examples

The following code sample creates an enumerator, and then uses the Current and MoveNext methods to navigate over the collection.

using System;  
using System.Collections;  
using System.Collections.Generic;  
using System.Text;  
using Microsoft.SqlServer.Dts.Runtime;  
using Microsoft.SqlServer.Dts.Runtime.Enumerators.Item;  

namespace ForEachEnums  
{  
    class Program  
    {  
        static void Main(string[] args)  
        {  
            Application app = new Application();  
            ForEachEnumeratorInfos feInfos = app.ForEachEnumeratorInfos;  

            //Create the Enumerator.  
            ForEachEnumeratorInfosEnumerator myEnumerator = feInfos.GetEnumerator();  
            Console.WriteLine("The collection contains the following values:");  
            int i = 0;  
            while ((myEnumerator.MoveNext()) && (myEnumerator.Current != null))  
                Console.WriteLine("[{0}] {1}", i++, myEnumerator.Current.Name);  
        }  
    }  
}  

Sample Output:

The collection contains the following values:

[0] For Each File Enumerator

[1] For Each Item Enumerator

[2] For Each ADO Enumerator

[3] For Each ADO.NET Schema Rowset Enumerator

[4] For Each From Variable Enumerator

[5] For Each NodeList Enumerator

[6] For Each SMO Enumerator

Remarks

After an enumerator is created, or after a call to the Reset method, the MoveNext method must be called to advance the enumerator to the first element of the collection before the enumerator can read the value of the Current property; otherwise, Current is undefined and throws an exception.

Current also throws an exception if the last call to MoveNext returned false, which indicates the end of the collection.

Current does not move the position of the enumerator, and consecutive calls to Current return the same object until either MoveNext or Reset is called.

An enumerator remains valid as long as the collection remains unchanged. If changes are made to the collection, such as adding, modifying, or deleting elements, the enumerator is invalidated and becomes irrecoverable; thus, the next call to MoveNext or Reset throws an InvalidOperationException. However, if the collection is modified between calls to MoveNext and Current, Current returns the element that it is set to, even if the enumerator has been invalidated.

Applies to