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

在集合中要找到的物件名稱、描述、ID 或索引 LogEntryInfo

傳回

一個布林值,指示該集合是否可以透過名稱、描述、ID 或索引存取。 值為 true 表示可透過語法 LogEntryInfos[index] 存取該集合。 值為 false 表示索引無法用來從集合中檢索項目 LogEntryInfos ;使用此特性會拋出例外。

範例

以下程式碼範例使用此 Contains 方法來判斷集合中是否包含名為「Diagnostic」的日誌條目。 該方法回傳一個 Boolean

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

namespace LogEntryInfosTest  
{  
    class Program  
    {  
        static void Main(string[] args)  
        {  
            // The package is one of the SSIS Samples.  
            string mySample = @"C:\Program Files\Microsoft SQL Server\100\Samples\Integration Services\Package Samples\CalculatedColumns Sample\CalculatedColumns\CalculatedColumns.dtsx";  

            // Create the Application, and load the sample.  
            Application app = new Application();  
            Package pkg = app.LoadPackage(mySample, null);  

            // Get the LogEntryInfos from the package.  
            LogEntryInfos logInfos = pkg.LogEntryInfos;  

            //See if the collection contains a LogEntryInfo named "Diagnostic".  
            Boolean logDiagnostic = logInfos.Contains("Diagnostic");  
            Console.WriteLine("Contains Diagnostic? {0}", logDiagnostic);  

            Console.WriteLine();  
        }  
    }  
}  
Imports System  
Imports System.Collections.Generic  
Imports System.Text  
Imports Microsoft.SqlServer.Dts.Runtime  

Namespace LogEnTryInfosTest  
    Class Program  
        Shared  Sub Main(ByVal args() As String)  
            ' The package is one of the SSIS Samples.  
            Dim mySample As String =  "C:\Program Files\Microsoft SQL Server\100\Samples\Integration Services\Package Samples\CalculatedColumns Sample\CalculatedColumns\CalculatedColumns.dtsx"   

            ' Create the Application, and load the sample.  
            Dim app As Application =  New Application()   
            Dim pkg As Package =  app.LoadPackage(mySample,Nothing)   

            ' Get the LogEntryInfos from the package.  
            Dim logInfos As LogEnTryInfos =  pkg.LogEnTryInfos   

            'See if the collection contains a LogEntryInfo named "Diagnostic".  
            Dim logDiagnostic As Boolean =  logInfos.Contains("Diagnostic")   
            Console.WriteLine("Contains Diagnostic? {0}", logDiagnostic)  

            Console.WriteLine()  
        End Sub  
    End Class  
End Namespace  

範例輸出:

包含診斷功能? 沒錯

適用於