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] Поток текста Unicode DT_NTEXT
содержит как минимум 30 типов данных? Неправда
содержит как минимум 20 типов данных? True