DataTypeInfos.Contains(Object) Metodo
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Restituisce un valore booleano che indica se è possibile accedere agli elementi della raccolta usando l'indicizzazione senza generare un'eccezione.
public:
bool Contains(System::Object ^ index);
public bool Contains (object index);
member this.Contains : obj -> bool
Public Function Contains (index As Object) As Boolean
Parametri
- index
- Object
Indice dell'elemento da individuare nella raccolta.
Restituisce
Valore booleano che indica se è possibile accedere alla raccolta in base all'indice. Un valore true indica che è possibile accedere alla raccolta usando la sintassi DataTypeInfos[index]. Un valore false indica che l'indicizzazione non può essere utilizzata per recuperare elementi dalla DataTypeInfos raccolta.
Esempio
Nell'esempio seguente viene utilizzato il Contains metodo per visualizzare il numero di elementi presenti nell'insieme.
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
Esempio di output
La raccolta contiene i valori seguenti:
[0] float DT_R4
[1] DT_R8 float a precisione doppia
[2] DT_CY di valuta
[3] data DT_DATE
[4] DT_BOOL booleano
[5] DT_DECIMAL decimali
[6] Intero con segno a byte singolo DT_I1
[7] Intero senza segno a byte singolo DT_UI1
[8] Intero con segno a due byte DT_I2
[9] Intero senza segno a due byte DT_UI2
[10] Intero con segno a quattro byte DT_I4
[11] Intero senza segno a quattro byte DT_UI4
[12] Intero con segno a otto byte DT_I8
[13] Intero senza segno a otto byte DT_UI8
[14] file timestamp DT_FILETIME
[15] identificatore univoco DT_GUID
[16] flusso di byte DT_BYTES
[17] stringa DT_STR
[18] Stringa Unicode DT_WSTR
[19] DT_NUMERIC numerici
[20] data del database DT_DBDATE
[21] tempo del database DT_DBTIME
[22] timestamp del database DT_DBTIMESTAMP
[23] immagine DT_IMAGE
[24] flusso di testo DT_TEXT
[25] Flusso di testo Unicode DT_NTEXT
contiene almeno 30 tipi di dati? Falso
contiene almeno 20 tipi di dati? Vero