ConnectionInfoEnumerator.Current 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取集合中的当前元素。
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
属性值
集合中的当前元素。
示例
下面的代码示例创建一个枚举器,然后使用CurrentMoveNext
和Reset
方法在集合上导航。
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
。
只要集合保持不变,枚举器就仍有效。 如果对集合进行了更改(例如添加、修改或删除元素),则枚举器将失效并变为不可恢复;因此,下一次调用 MoveNext
或 Reset
引发一个 InvalidOperationException
。 如果对集合的调用 MoveNext
和 Current调用之间修改, Current 则返回它设置为的元素,即使枚举器已失效。