DataTypeInfoEnumerator.Current 属性

定义

获取集合中的当前元素。

public:
 property System::Object ^ Current { System::Object ^ get(); };
public object Current { get; }
member this.Current : obj
Public ReadOnly Property Current As Object

属性值

集合中的当前元素。

实现

示例

下面的代码示例创建一个枚举器,然后使用CurrentMoveNextReset方法在集合上导航。

using System;  
using System.Collections.Generic;  
using System.Text;  
using Microsoft.SqlServer.Dts.Runtime;  
namespace DataTypeInfos_GetEnum_Current  
{  
    class Program  
    {  
        static void Main(string[] args)  
        {  
            //Create the DataTypeInfos collection.  
            DataTypeInfos dataInfos = new Application().DataTypeInfos;  

            //Create the Enumerator.  
            DataTypeInfoEnumerator myEnumerator = dataInfos.GetEnumerator();  
            Console.WriteLine("The collection contains the following values:");  
            int i = 0;  
            DataTypeInfo dtiObject;  
            while ((myEnumerator.MoveNext()) && (myEnumerator.Current != null))  
            {  
                dtiObject = (DataTypeInfo)myEnumerator.Current;  
                Console.WriteLine("[{0}] {1} {2}", i++, dtiObject.TypeName, dtiObject.TypeEnumName);  
            }  
            // Reset puts the index pointer before the beginning.  
            // Do not retrieve from the collection until MoveNext is called.  
            myEnumerator.Reset();  
            myEnumerator.MoveNext();  
            // Now that the enumerator has been reset, and moved to the  
            // first item in the collection, show the first item.  
            dtiObject = (DataTypeInfo)myEnumerator.Current;  
            Console.WriteLine("The first item in the enumerator after Reset:");  
            Console.WriteLine("{0}, {1}", dtiObject.TypeName, dtiObject.TypeEnumName);  
        }  
    }  
}  
Imports System  
Imports System.Collections.Generic  
Imports System.Text  
Imports Microsoft.SqlServer.Dts.Runtime  

Namespace DataTypeInfos_GetEnum_Current  
    Class Program  
        Shared  Sub Main(ByVal args() As String)  
            'Create the DataTypeInfos collection.  
            Dim dataInfos As DataTypeInfos =  New Application().DataTypeInfos   

            'Create the Enumerator.  
            Dim myEnumerator As DataTypeInfoEnumerator =  dataInfos.GetEnumerator()   
            Console.WriteLine("The collection contains the following values:")  
            Dim i As Integer =  0   
            Dim dtiObject As DataTypeInfo  
            While (myEnumerator.MoveNext()) &&(myEnumerator.Current <> Nothing)  
                dtiObject = CType(myEnumerator.Current, DataTypeInfo)  
                Console.WriteLine("[{0}] {1} {2}",i = Console.WriteLine("[{0}] {1} {2}",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()  
            ' Now that the enumerator has been reset, and moved to the  
            ' first item in the collection, show the first item.  
            dtiObject = CType(myEnumerator.Current, DataTypeInfo)  
            Console.WriteLine("The first item in the enumerator after Reset:")  
            Console.WriteLine("{0}, {1}", dtiObject.TypeName, dtiObject.TypeEnumName)  
        End Sub  
    End Class  
End Namespace  

示例输出:

集合包含以下值:

[0] float DT_R4

[1] 双精度浮点数DT_R8

[2] 货币DT_CY

[3] 日期DT_DATE

[4] 布尔DT_BOOL

[5] 十进制DT_DECIMAL

[6] 单字节有符号整数DT_I1

[7] 单字节无符号整数DT_UI1

[8] 双字节有符号整数DT_I2

[9] 双字节无符号整数DT_UI2

[10] 四字节有符号整数DT_I4

[11] 四字节无符号整数DT_UI4

[12] 八字节有符号整数DT_I8

[13] 8 字节无符号整数DT_UI8

[14] 文件时间戳DT_FILETIME

[15] 唯一标识符DT_GUID

[16] 字节流DT_BYTES

[17] 字符串DT_STR

[18] Unicode 字符串DT_WSTR

[19] 数值DT_NUMERIC

[20] 数据库日期DT_DBDATE

[21] 数据库时间DT_DBTIME

[22] 数据库时间戳DT_DBTIMESTAMP

[23] 图像DT_IMAGE

[24] 文本流DT_TEXT

[25] Unicode 文本流DT_NTEXT

重置后枚举器中的第一项:

float、DT_R4

注解

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

Current如果最后一次调用返回MoveNextfalse,则也会引发异常,该调用指示集合的末尾。

Current在调用或调用之前,不移动枚举器的位置,并且连续调用返回Current相同的对象MoveNextReset

只要集合保持不变,枚举器就仍有效。 如果对集合进行了更改(例如添加、修改或删除元素),则枚举器将失效并变为不可恢复。 如果对集合的调用 MoveNextCurrent调用之间修改, Current 则返回它设置为的元素,即使枚举器已失效。

适用于