DataTypeInfos.Contains(Object) Metode
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Mengembalikan Boolean yang menunjukkan apakah item dalam koleksi dapat diakses menggunakan pengindeksan tanpa melemparkan pengecualian.
public:
bool Contains(System::Object ^ index);
public bool Contains (object index);
member this.Contains : obj -> bool
Public Function Contains (index As Object) As Boolean
Parameter
- index
- Object
Indeks item yang akan ditemukan dalam koleksi.
Mengembalikan
Boolean yang menunjukkan apakah koleksi dapat diakses oleh indeks. Nilai true menunjukkan bahwa koleksi dapat diakses menggunakan sintaks DataTypeInfos[index]. Nilai false menunjukkan bahwa pengindeksan tidak dapat digunakan untuk mengambil item dari DataTypeInfos koleksi.
Contoh
Contoh berikut menggunakan Contains metode untuk melihat berapa banyak item dalam koleksi.
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
Contoh Output:
Koleksi berisi nilai berikut:
[0] float DT_R4
[1] float presisi ganda DT_R8
[2] DT_CY mata uang
[3] tanggal DT_DATE
[4] Boolean DT_BOOL
[5] DT_DECIMAL desimal
[6] bilangan bulat bertanda tangan byte tunggal DT_I1
[7] bilangan bulat tunggal yang tidak ditandatangani DT_UI1
[8] bilangan bulat bertanda tangan dua byte DT_I2
[9] bilangan bulat dua byte yang tidak ditandatangani DT_UI2
[10] bilangan bulat bertanda empat byte DT_I4
[11] bilangan bulat empat byte yang tidak ditandatangani DT_UI4
[12] bilangan bulat bertanda tangan delapan byte DT_I8
[13] bilangan bulat delapan byte yang tidak ditandatangani DT_UI8
[14] tanda waktu file DT_FILETIME
[15] pengidentifikasi unik DT_GUID
[16] aliran byte DT_BYTES
[17] string DT_STR
[18] String Unicode DT_WSTR
[19] DT_NUMERIC numerik
[20] tanggal database DT_DBDATE
[21] waktu database DT_DBTIME
[22] tanda waktu database DT_DBTIMESTAMP
[23] gambar DT_IMAGE
[24] aliran teks DT_TEXT
[25] Aliran teks Unicode DT_NTEXT
berisi setidaknya 30 jenis data? FALSE
berisi setidaknya 20 jenis data? True