DataTypeInfos.Contains(Object) Método

Definición

Devuelve un valor Boolean que indica si se puede tener acceso a los elementos de la colección mediante la indexación sin producir una excepción.

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

Parámetros

index
Object

El índice del elemento para ubicar en la colección.

Devoluciones

Valor booleano que indica si se puede tener acceso a la colección por índice. Un valor true indica que se puede tener acceso a la colección mediante la sintaxis DataTypeInfos[index]. Un valor false indica que no se puede usar la indexación para recuperar elementos de la DataTypeInfos colección.

Ejemplos

En el ejemplo siguiente se usa el Contains método para ver cuántos elementos hay en la colección.

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  

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

contiene al menos 30 tipos de datos? Falso

contiene al menos 20 tipos de datos? Verdadero

Se aplica a