DataTypeInfos.GetEnumerator 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
返回可遍历 DataTypeInfoEnumerator 集合的 DataTypeInfo。
public:
Microsoft::SqlServer::Dts::Runtime::DataTypeInfoEnumerator ^ GetEnumerator();
public Microsoft.SqlServer.Dts.Runtime.DataTypeInfoEnumerator GetEnumerator ();
override this.GetEnumerator : unit -> Microsoft.SqlServer.Dts.Runtime.DataTypeInfoEnumerator
Public Function GetEnumerator () As DataTypeInfoEnumerator
返回
DataTypeInfoEnumerator 集合的 DataTypeInfo。
示例
下面的代码示例使用GetEnumerator该方法创建一个DataTypeInfoEnumerator,然后循环访问集合。
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