DataTypeInfos.Contains Method
Returns a Boolean that indicates whether the items in the collection can be accessed using indexing without throwing an exception.
命名空間: Microsoft.SqlServer.Dts.Runtime
組件: Microsoft.SqlServer.ManagedDTS (in microsoft.sqlserver.manageddts.dll)
語法
'宣告
Public Function Contains ( _
index As Object _
) As Boolean
public bool Contains (
Object index
)
public:
bool Contains (
Object^ index
)
public boolean Contains (
Object index
)
public function Contains (
index : Object
) : boolean
參數
- index
The index of the item to locate in the collection.
傳回值
A Boolean that indicates whether the collection can be accessed by index. A value of true indicates that the collection can be accessed using the syntax DataTypeInfos[index]
. A value of false indicates that indexing cannot be used to retrieve items from the DataTypeInfos collection.
範例
The following example uses the Contains method to see how many items are in the collection.
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
Sample Output:
The collection contains the following values:
[0] float DT_R4
[1] double-precision float DT_R8
[2] currency DT_CY
[3] date DT_DATE
[4] Boolean DT_BOOL
[5] decimal DT_DECIMAL
[6] single-byte signed integer DT_I1
[7] single-byte unsigned integer DT_UI1
[8] two-byte signed integer DT_I2
[9] two-byte unsigned integer DT_UI2
[10] four-byte signed integer DT_I4
[11] four-byte unsigned integer DT_UI4
[12] eight-byte signed integer DT_I8
[13] eight-byte unsigned integer DT_UI8
[14] file timestamp DT_FILETIME
[15] unique identifier DT_GUID
[16] byte stream DT_BYTES
[17] string DT_STR
[18] Unicode string DT_WSTR
[19] numeric DT_NUMERIC
[20] database date DT_DBDATE
[21] database time DT_DBTIME
[22] database timestamp DT_DBTIMESTAMP
[23] image DT_IMAGE
[24] text stream DT_TEXT
[25] Unicode text stream DT_NTEXT
contains at least 30 data types? False
contains at least 20 data types? True
執行緒安全性
Any public static (Shared in Microsoft Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
平台
開發平台
如需受支援的平台清單,請參閱<安裝 SQL Server 2005 的硬體和軟體需求>。
目標平台
如需受支援的平台清單,請參閱<安裝 SQL Server 2005 的硬體和軟體需求>。
請參閱
參考
DataTypeInfos Class
DataTypeInfos Members
Microsoft.SqlServer.Dts.Runtime Namespace