Язык

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  

Пример вывода:

Коллекция содержит следующие значения:

[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] восьмибайтный беззнаковый целочисленный DT_UI8

[14] Временная метка файла DT_FILETIME

[15] уникальный идентификатор DT_GUID

[16] байтовый поток DT_BYTES

[17] струнная DT_STR

[18] Строка Юникода DT_WSTR

[19] числовые DT_NUMERIC

[20] дата базы данных DT_DBDATE

[21] Время базы данных DT_DBTIME

[22] Временная метка базы данных DT_DBTIMESTAMP

[23] Изображение DT_IMAGE

[24] текстовый поток DT_TEXT

[25] Поток текста Unicode DT_NTEXT

Первый элемент в переписчике после сброса:

Парить, DT_R4

Комментарии

После создания переписчика или после вызова Reset метода, MoveNext метод должен быть вызван для продвижения переписчика к первому элементу коллекции перед чтением значения Current свойства; в противном случае Current метод не определён и создаёт исключение.

Current также вызывает исключение, если последний вызов MoveNext возвращаемого falseобъекта, указывающий конец коллекции.

Current не перемещает положение переписчика, и последовательные вызовы Current возвращают тот же объект, пока не будет вызвано либо или MoveNextReset .

Перечислитель остается допустимым, пока коллекция остается неизменной. Если в коллекцию вносятся изменения, такие как добавление, изменение или удаление элементов, переписчик аннулируется и становится невосстановимым. Если коллекция изменяется между вызовами MoveNext и Current, Current возвращает элемент, на который она настроена, даже если переписчик был аналирован.

Применяется к