ExecutableEnumerator.Current 属性  
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取集合中的当前元素。
public:
 property Microsoft::SqlServer::Dts::Runtime::Executable ^ Current { Microsoft::SqlServer::Dts::Runtime::Executable ^ get(); };public Microsoft.SqlServer.Dts.Runtime.Executable Current { get; }member this.Current : Microsoft.SqlServer.Dts.Runtime.ExecutablePublic ReadOnly Property Current As Executable属性值
集合中的当前元素。
示例
The following code example adds a Bulk Insert task to the package, retrieves the Executables collection, creates an enumerator, and shows the name using the TaskHost.
using System;  
using System.Collections.Generic;  
using System.Text;  
using Microsoft.SqlServer.Dts.Runtime;  
namespace Executables_API  
{  
    class Program  
    {  
        static void Main(string[] args)  
        {  
            // Create the package and add the BulkInsertTask.  
            Package pkg = new Package();  
            Executable exec = pkg.Executables.Add("STOCK:BulkInsertTask");  
            // Obtain the collection.  
            Executables pgkExecs = pkg.Executables;  
            //Create the Enumerator.  
            ExecutableEnumerator myEnumerator = pgkExecs.GetEnumerator();  
            Console.WriteLine("The collection contains the following values:");  
            int i = 0;  
            Executable myExec;  
            TaskHost myTH;  
            while ((myEnumerator.MoveNext()) && (myEnumerator.Current != null))  
            {  
                myExec = (Executable)myEnumerator.Current;  
                myTH = (TaskHost)myExec;  
                Console.WriteLine("[{0}] {1}", i++, myTH.Name);  
            }  
            // Reset puts the index pointer before the beginning.  
            // Do not retrieve from the collection until MoveNext is called.  
            myEnumerator.Reset();  
            myEnumerator.MoveNext();  
        }  
    }  
}  
Imports System  
Imports System.Collections.Generic  
Imports System.Text  
Imports Microsoft.SqlServer.Dts.Runtime  
Namespace Executables_API  
    Class Program  
        Shared  Sub Main(ByVal args() As String)  
            ' Create the package and add the BulkInsertTask.  
            Dim pkg As Package =  New Package()   
            Dim exec As Executable =  pkg.Executables.Add("STOCK:BulkInsertTask")   
            ' Obtain the collection.  
            Dim pgkExecs As Executables =  pkg.Executables   
            'Create the Enumerator.  
            Dim myEnumerator As ExecutableEnumerator =  pgkExecs.GetEnumerator()   
            Console.WriteLine("The collection contains the following values:")  
            Dim i As Integer =  0   
            Dim myExec As Executable  
            Dim myTH As TaskHost  
            While (myEnumerator.MoveNext()) &&(myEnumerator.Current <> Nothing)  
                myExec = CType(myEnumerator.Current, Executable)  
                myTH = CType(myExec, TaskHost)  
                Console.WriteLine("[{0}] {1}",i = Console.WriteLine("[{0}] {1}",i + 1  
            End While  
            ' Reset puts the index pointer before the beginning.  
            ' Do not retrieve from the collection until MoveNext is called.  
            myEnumerator.Reset()  
            myEnumerator.MoveNext()  
         End Sub  
    End Class  
End Namespace  
示例输出:
集合包含以下值:
[0] {C435F0C7-97E8-4DCC-A0FF-C6C805D9F64E}
注解
创建枚举器或调用 Reset 方法后, MoveNext 必须调用该方法才能将枚举器推进到集合的第一个元素,然后枚举器才能读取属性的值 Current ;否则, Current 未定义并引发异常。
              Current如果最后一次调用返回MoveNextfalse,则也会引发异常,该调用指示集合的末尾。
              Current不会移动枚举器的位置,并且连续调用以Current返回相同的对象,直到调用或MoveNextReset调用。
只要集合保持不变,枚举器就仍有效。 如果对集合进行了更改(例如添加、修改或删除元素),则枚举器将失效并变为不可恢复;因此,下一次调用 MoveNext 或 Reset 引发异常。 但是,如果在调用 MoveNext 和 Current调用之间修改集合, Current 则返回它设置为的元素,即使枚举器已失效也是如此。