Executables.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

Executable 对象的索引。

返回

如果可以使用语法可执行文件[索引]检索项,则为 true;如果索引不能用于从集合中检索项, Executables 则为 false。

示例

下面的代码示例将大容量插入任务添加为可执行文件,然后用于 Contains 验证包中至少有一个可执行文件的存在。

using System;  
using System.Collections.Generic;  
using System.Text;  
using Microsoft.SqlServer.Dts.Runtime;  

namespace Executables_API  
{  
        class Program  
        {  
        static void Main(string[] args)  
        {  
            Package pkg = new Package();  
            Executable exec = pkg.Executables.Add("STOCK:BulkInsertTask");  

            // Obtain the collection.  
            Executables pgkExecs = pkg.Executables;  
            foreach (Executable eachExec in pgkExecs)  
            {  
                TaskHost th = exec as TaskHost;  
                Console.WriteLine("Executable creation name is: {0}", th.CreationName);  
            }  

            // Show use of Contains.  
            if (pgkExecs.Contains(0))  
            {  
                Console.WriteLine("Contains returned true");  
            }  
            else  
            {  
                Console.WriteLine("Contains returned false");  
            }  
        }  
    }  
}  
Imports System  
Imports System.Collections.Generic  
Imports System.Text  
Imports Microsoft.SqlServer.Dts.Runtime  

Namespace Executables_API  
        Class Program  
        Shared  Sub Main(ByVal args() As String)  
            Dim pkg As Package =  New Package()   
            Dim exec As Executable =  pkg.Executables.Add("STOCK:BulkInsertTask")   

            ' Obtain the collection.  
            Dim pgkExecs As Executables =  pkg.Executables   
            Dim eachExec As Executable  
            For Each eachExec In pgkExecs  
                Dim th As TaskHost =  exec as TaskHost   
                Console.WriteLine("Executable creation name is: {0}", th.CreationName)  
            Next  

            ' Show use of Contains.  
            If pgkExecs.Contains(0) Then  
                Console.WriteLine("Contains returned true")  
            Else   
                Console.WriteLine("Contains returned false")  
            End If  
        End Sub  
        End Class  
End Namespace  

示例输出:

Executable creation name is: Microsoft.SqlServer.Dts.Tasks.BulkInsertTask.BulkInsertTask, Microsoft.SqlServer.BulkInsertTask, Version=10.0.000.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91

Contains returned true

适用于