Bagikan melalui


DataTypeInfoEnumerator.Current Properti

Definisi

Mendapatkan elemen saat ini dalam koleksi.

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

Nilai Properti

Elemen saat ini dalam koleksi.

Penerapan

Contoh

Sampel kode berikut membuat enumerator, lalu menggunakan Currentmetode , MoveNext, dan Reset untuk menavigasi koleksi.

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  

Contoh Output:

Koleksi berisi nilai berikut:

[0] float DT_R4

[1] float presisi ganda DT_R8

[2] DT_CY mata uang

[3] tanggal DT_DATE

[4] Boolean DT_BOOL

[5] DT_DECIMAL desimal

[6] bilangan bulat bertanda tangan byte tunggal DT_I1

[7] bilangan bulat tunggal yang tidak ditandatangani DT_UI1

[8] bilangan bulat bertanda tangan dua byte DT_I2

[9] bilangan bulat dua byte yang tidak ditandatangani DT_UI2

[10] bilangan bulat bertanda empat byte DT_I4

[11] bilangan bulat empat byte yang tidak ditandatangani DT_UI4

[12] bilangan bulat bertanda tangan delapan byte DT_I8

[13] bilangan bulat delapan byte yang tidak ditandatangani DT_UI8

[14] tanda waktu file DT_FILETIME

[15] pengidentifikasi unik DT_GUID

[16] aliran byte DT_BYTES

[17] string DT_STR

[18] String Unicode DT_WSTR

[19] DT_NUMERIC numerik

[20] tanggal database DT_DBDATE

[21] waktu database DT_DBTIME

[22] tanda waktu database DT_DBTIMESTAMP

[23] gambar DT_IMAGE

[24] aliran teks DT_TEXT

[25] Aliran teks Unicode DT_NTEXT

Item pertama dalam enumerator setelah Reset:

float, DT_R4

Keterangan

Setelah enumerator dibuat, atau setelah panggilan ke Reset metode , MoveNext metode harus dipanggil untuk memajukan enumerator ke elemen pertama koleksi sebelum membaca nilai Current properti; jika tidak, Current tidak terdefinisi dan melempar pengecualian.

Current juga melemparkan pengecualian jika panggilan terakhir untuk MoveNext dikembalikan false, yang menunjukkan akhir koleksi.

Current tidak memindahkan posisi enumerator, dan panggilan berturut-turut ke Current mengembalikan objek yang sama sampai atau MoveNextReset dipanggil.

Enumerator tetap valid selama koleksi tetap tidak berubah. Jika perubahan dilakukan pada koleksi, seperti menambahkan, memodifikasi, atau menghapus elemen, enumerator tidak valid dan menjadi tidak dapat dipulihkan. Jika koleksi dimodifikasi antara panggilan ke MoveNext dan Current, Current mengembalikan elemen yang diatur ke, bahkan jika enumerator telah dibatalkan.

Berlaku untuk