DataTypeInfoEnumerator.Current Proprietà

Definizione

Ottiene l'elemento corrente nella raccolta.

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

Valore della proprietà

Object

Elemento corrente nella raccolta.

Implementazioni

Esempio

Nell'esempio di codice seguente viene creato un enumeratore, quindi vengono utilizzati i Current MoveNext metodi, e Reset per spostarsi nella raccolta.

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  

Esempio di output:

La raccolta contiene i valori seguenti:

[0] float DT_R4

[1] float a precisione doppia DT_R8

[2] valuta DT_CY

[3] data DT_DATE

[4] valore booleano DT_BOOL

[5] decimale DT_DECIMAL

[6] intero con segno a byte singolo DT_I1

[7] Unsigned Integer a byte singolo DT_UI1

[8] intero con segno a due byte DT_I2

[9] Unsigned Integer a due byte DT_UI2

[10] intero con segno a quattro byte DT_I4

[11] Unsigned Integer a quattro byte DT_UI4

[12] intero con segno a otto byte DT_I8

[13] Unsigned Integer a otto byte DT_UI8

[14] timestamp del file DT_FILETIME

[15] identificatore univoco DT_GUID

[16] flusso di byte DT_BYTES

[17] stringa DT_STR

[18] stringa Unicode DT_WSTR

[19] numeric DT_NUMERIC

[20] data DT_DBDATE database

[21] ora database DT_DBTIME

[22] timestamp del database DT_DBTIMESTAMP

[23] DT_IMAGE immagine

[24] flusso di testo DT_TEXT

[25] flusso di testo Unicode DT_NTEXT

Primo elemento nell'enumeratore dopo la reimpostazione:

float, DT_R4

Commenti

Dopo la creazione di un enumeratore o dopo una chiamata al Reset metodo, MoveNext è necessario chiamare il metodo per far avanzare l'enumeratore al primo elemento della raccolta prima di leggere il valore della Current Proprietà; in caso contrario, non Current è definito e genera un'eccezione.

Currentgenera inoltre un'eccezione se l'ultima chiamata a MoveNext restituisce false , che indica la fine della raccolta.

Currentnon sposta la posizione dell'enumeratore e le chiamate consecutive a Current restituiscono lo stesso oggetto fino a quando non MoveNext viene chiamato il metodo o Reset .

Un enumeratore rimane valido finché la raccolta rimane invariata. Se vengono apportate modifiche alla raccolta, ad esempio l'aggiunta, la modifica o l'eliminazione di elementi, l'enumeratore viene invalidato e diventa irreversibile. Se la raccolta viene modificata tra le chiamate a MoveNext e Current , Current restituisce l'elemento su cui è impostata, anche se l'enumeratore è stato invalidato.

Si applica a