Share via


DataTypeInfoEnumerator.Reset 方法

定义

将枚举数设置为其初始位置,该位置位于集合中第一个元素之前。

public:
 virtual void Reset();
public void Reset ();
abstract member Reset : unit -> unit
override this.Reset : unit -> unit
Public Sub Reset ()

实现

示例

下面的代码示例创建一个枚举器,然后使用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

适用于