语言

ConnectionInfoEnumerator.Current 属性

定义

获取集合中的当前元素。

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

属性值

集合中的当前元素。

示例

以下代码示例创建一个枚举器,然后使用 CurrentMoveNextReset 方法来浏览集合。

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

namespace ConnInfos_Current  
{  
    class Program  
    {  
        static void Main(string[] args)  
        {  
            Application dtsApplication = new Application();  
            ConnectionInfos connectionInfos = dtsApplication.ConnectionInfos;  

            //Create the Enumerator.  
            ConnectionInfoEnumerator ConnInfoEnum = connectionInfos.GetEnumerator();  
            Console.WriteLine("The collection contains the following values:");  
            int i = 0;  
            while ((ConnInfoEnum.MoveNext()) && (ConnInfoEnum.Current != null))  
                Console.WriteLine("[{0}] {1}", i++, ConnInfoEnum.Current.Name);  
        }  
    }  
}  
Imports System  
Imports System.Collections.Generic  
Imports System.Text  
Imports Microsoft.SqlServer.Dts.Runtime  

Namespace ConnInfos_Current  
    Class Program  
        Shared  Sub Main(ByVal args() As String)  
            Dim dtsApplication As Application =  New Application()   
            Dim connectionInfos As ConnectionInfos =  dtsApplication.ConnectionInfos   

            'Create the Enumerator.  
            Dim ConnInfoEnum As ConnectionInfoEnumerator =  connectionInfos.GetEnumerator()   
            Console.WriteLine("The collection contains the following values:")  
            Dim i As Integer =  0   
            While (ConnInfoEnum.MoveNext()) &&(ConnInfoEnum.Current <> Nothing)  
            Console.WriteLine("[{0}] {1}",i = Console.WriteLine("[{0}] {1}",i + 1  
            End While  
        End Sub  
    End Class  
End Namespace  

示例输出:

The collection contains the following values:

[0] Connection Manager for Files

[1] Connection Manager for SQL Server Compact

[2] Connection Manager for Multiple Flat Files

注解

在创建枚举器或调用该方法后 Reset ,必须先调用该 MoveNext 方法,将枚举器推进到集合的第一个元素,然后才能读取属性的 Current 值;否则,为 Current 未定义并抛出异常。

Current 如果最后一次调用 MoveNext 返回 false,则也会引发异常,这表示集合的末尾。

Current 不会移动枚举器的位置,连续调用 返回 Current 同一对象,直到 MoveNext 被调用 或 Reset

只要集合保持不变,枚举器就保持有效。 如果对集合进行了更改,比如添加、修改或删除元素,枚举器将失效并无法恢复;因此,下一次调用 MoveNextReset 会抛出 InvalidOperationException。 如果集合在调用和MoveNextCurrent之间被修改,Current则返回其设定的元素,即使枚举器已被失效。

适用于