DataTypeInfoEnumerator.Current プロパティ

定義

コレクション内の現在の要素を取得します。

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

プロパティ値

コレクション内にある現在の要素です。

実装

次のコード サンプルでは、列挙子を作成してから、Current メソッド、MoveNext メソッド、および Reset メソッドを使用してコレクションを移動します。

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  

サンプル出力:

The collection contains the following values:

[0] float DT_R4

[1] double-precision float DT_R8

[2] currency DT_CY

[3] date DT_DATE

[4] Boolean DT_BOOL

[5] decimal DT_DECIMAL

[6] single-byte signed integer DT_I1

[7] single-byte unsigned integer DT_UI1

[8] two-byte signed integer DT_I2

[9] two-byte unsigned integer DT_UI2

[10] four-byte signed integer DT_I4

[11] four-byte unsigned integer DT_UI4

[12] eight-byte signed integer DT_I8

[13] eight-byte unsigned integer DT_UI8

[14] file timestamp DT_FILETIME

[15] unique identifier DT_GUID

[16] byte stream DT_BYTES

[17] string DT_STR

[18] Unicode string DT_WSTR

[19] numeric DT_NUMERIC

[20] database date DT_DBDATE

[21] database time DT_DBTIME

[22] database timestamp DT_DBTIMESTAMP

[23] image DT_IMAGE

[24] text stream DT_TEXT

[25] Unicode text stream DT_NTEXT

The first item in the enumerator after Reset:

float, DT_R4

注釈

列挙子を作成した後や Reset メソッドを呼び出した後は、Current プロパティの値を読み取る前に、MoveNext メソッドを呼び出して列挙子をコレクションの先頭の要素に進めておく必要があります。そうしないと、Current は未定義となり、例外がスローされます。

前回の MoveNext の呼び出しで false が返された場合 (コレクションの末尾であることを示します)、その後で Current を呼び出しても例外がスローされます。

Current は列挙子の位置を移動しません。Current を連続して呼び出すと、MoveNext または Reset が呼び出されるまで同じオブジェクトが返されます。

列挙子は、コレクションが変更されない限り有効です。 要素の追加、変更、削除など、コレクションに変更が加えられた場合は、列挙子は無効になり回復できなくなります。 コレクションが呼び出しと呼び出しCurrentの間でMoveNext変更された場合は、Current列挙子が無効になっている場合でも、設定されている要素を返します。

適用対象