Share via


DataTypeInfoEnumerator.Current Propiedad

Definición

Obtiene el elemento actual de la colección.

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

Valor de propiedad

Elemento actual de la colección.

Implementaciones

Ejemplos

En el ejemplo de código siguiente se crea un enumerador y, a continuación, se usan los Currentmétodos , MoveNexty Reset para navegar por la colección.

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  

Salida del ejemplo:

La colección contiene los siguientes valores:

[0] DT_R4 float

[1] DT_R8 float de precisión doble

[2] DT_CY de moneda

[3] DT_DATE de fecha

[4] DT_BOOL booleano

[5] DT_DECIMAL decimal

[6] entero con signo de un solo byte DT_I1

[7] entero de un solo byte sin signo DT_UI1

[8] entero con signo de dos bytes DT_I2

[9] entero sin signo de dos bytes DT_UI2

[10] entero con signo de cuatro bytes DT_I4

[11] entero de cuatro bytes sin signo DT_UI4

[12] entero con signo de ocho bytes DT_I8

[13] entero sin signo de ocho bytes DT_UI8

[14] marca de tiempo de archivo DT_FILETIME

[15] identificador único DT_GUID

[16] secuencia de bytes DT_BYTES

[17] DT_STR de cadena

[18] DT_WSTR de cadena Unicode

[19] DT_NUMERIC numérico

[20] fecha de base de datos DT_DBDATE

[21] DT_DBTIME de tiempo de base de datos

[22] DT_DBTIMESTAMP de marca de tiempo de base de datos

[23] DT_IMAGE de imagen

[24] flujo de texto DT_TEXT

[25] Flujo de texto Unicode DT_NTEXT

El primer elemento del enumerador después de Reset:

float, DT_R4

Comentarios

Después de crear un enumerador, o después de una llamada al Reset método , MoveNext se debe llamar al método para avanzar el enumerador al primer elemento de la colección antes de leer el valor de la Current propiedad; de lo contrario, Current no está definido y produce una excepción.

Currenttambién produce una excepción si se devuelve falsela última llamada a MoveNext , que indica el final de la colección.

Currentno mueve la posición del enumerador y las llamadas consecutivas al objeto devuelven el mismo objeto hasta que MoveNext se llama a Current o Reset .

Un enumerador sigue siendo válido mientras la colección permanezca inalterada. Si se realizan cambios en la colección, como agregar, modificar o eliminar elementos, el enumerador se invalida y se convierte en irrecuperable. Si la colección se modifica entre las llamadas a MoveNext y Current, Current devuelve el elemento en el que se establece, incluso si el enumerador se ha invalidado.

Se aplica a