Поделиться через


DataTypeInfos.Contains(Object) Метод

Определение

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

public:
 bool Contains(System::Object ^ index);
public bool Contains (object index);
member this.Contains : obj -> bool
Public Function Contains (index As Object) As Boolean

Параметры

index
Object

Индекс элемента, который необходимо найти в коллекции.

Возвращаемое значение

Логическое значение, указывающее, можно ли получить доступ к коллекции по индексу. Значение true указывает, что доступ к коллекции можно получить с помощью синтаксиса DataTypeInfos[index]. Значение false указывает, что индексирование нельзя использовать для извлечения элементов из DataTypeInfos коллекции.

Примеры

В следующем примере метод используется Contains для просмотра количества элементов в коллекции.

using System;  
using System.Collections.Generic;  
using System.Text;  
using Microsoft.SqlServer.Dts.Runtime;  

namespace DBProvInfos_GetEnum_Contains  
{  
    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, use Contains.  
            //Boolean contains30 = dataInfos.Contains(30);  
            Console.WriteLine("contains at least 30 data types? {0}", dataInfos.Contains(30));  
            Console.WriteLine("contains at least 20 data types? {0}", dataInfos.Contains(20));  
            // 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);  
            Console.WriteLine();  
        }  
    }  
}  
Imports System  
Imports System.Collections.Generic  
Imports System.Text  
Imports Microsoft.SqlServer.Dts.Runtime  

Namespace DBProvInfos_GetEnum_Contains  
    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, use Contains.  
            'Boolean contains30 = dataInfos.Contains(30);  
            Console.WriteLine("contains at least 30 data types? {0}", dataInfos.Contains(30))  
            Console.WriteLine("contains at least 20 data types? {0}", dataInfos.Contains(20))  

            ' 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);  
            Console.WriteLine()  
        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] Текстовый поток Юникода DT_NTEXT

содержит не менее 30 типов данных? Неверно

содержит не менее 20 типов данных? True

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