DtsEventHandlers.Item[Object] 属性   
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
从集合中获取一个 DtsEventHandler 对象。
public:
 property Microsoft::SqlServer::Dts::Runtime::DtsEventHandler ^ default[System::Object ^] { Microsoft::SqlServer::Dts::Runtime::DtsEventHandler ^ get(System::Object ^ index); };public Microsoft.SqlServer.Dts.Runtime.DtsEventHandler this[object index] { get; }member this.Item(obj) : Microsoft.SqlServer.Dts.Runtime.DtsEventHandlerDefault Public ReadOnly Property Item(index As Object) As DtsEventHandler参数
- index
- Object
要从集合中返回的 DtsEventHandler 对象的名称、ID 或索引。
属性值
来自集合的一个 DtsEventHandler 对象。
示例
下面的代码示例检索 DtsEventHandlers 集合,然后用于 Contains 查看是否可以对集合使用项语法 [x] 。
using System;  
using System.Collections.Generic;  
using System.Text;  
using Microsoft.SqlServer.Dts.Runtime;  
namespace Microsoft.SqlServer.SSIS.Samples  
{  
    class Program  
    {  
        static void Main(string[] args)  
        {  
            Package pkg = new Package();  
            // Set up a DtsEventHandler for the OnError event of the package.  
            DtsEventHandler dtsEHOE = (DtsEventHandler)pkg.EventHandlers.Add("OnError");  
            DtsEventHandler dtsEHW = (DtsEventHandler)pkg.EventHandlers.Add("OnWarning");  
            // Create the DtsEventHandlers collection.  
            DtsEventHandlers dtsEHColls = pkg.EventHandlers;  
            // Use the Contains method to see if the item[x] syntax can be used.  
            Boolean dtsContains = dtsEHColls.Contains(0);  
            Console.WriteLine("Item syntax can be used?  {0}", dtsContains);  
            //Using the Item method syntax of [x], obtain the first entry and a name.  
            DtsEventHandler dtsEHFirstEntry = dtsEHColls[0];  
            String nameOfFirstItem = dtsEHColls[0].Name;  
            //Print the name of the log provider object located at position [0].  
            Console.WriteLine("The ID of the first event handler is: {0}", dtsEHFirstEntry.ID);  
            Console.WriteLine("The Name of the first event handler is: {0}", nameOfFirstItem);  
        }  
    }  
}  
Imports System  
Imports System.Collections.Generic  
Imports System.Text  
Imports Microsoft.SqlServer.Dts.Runtime  
Namespace Microsoft.SqlServer.SSIS.Samples  
    Class Program  
        Shared  Sub Main(ByVal args() As String)  
            Dim pkg As Package =  New Package()   
            ' Set up a DtsEventHandler for the OnError event of the package.  
            Dim dtsEHOE As DtsEventHandler = CType(pkg.EventHandlers.Add("OnError"), DtsEventHandler)  
            Dim dtsEHW As DtsEventHandler = CType(pkg.EventHandlers.Add("OnWarning"), DtsEventHandler)  
            ' Create the DtsEventHandlers collection.  
            Dim dtsEHColls As DtsEventHandlers =  pkg.EventHandlers   
            ' Use the Contains method to see if the item[x] syntax can be used.  
            Dim dtsContains As Boolean =  dtsEHColls.Contains(0)   
            Console.WriteLine("Item syntax can be used?  {0}", dtsContains)  
            'Using the Item method syntax of [x], obtain the first entry and a name.  
            Dim dtsEHFirstEnTry As DtsEventHandler =  dtsEHColls(0)   
            Dim nameOfFirstItem As String =  dtsEHColls(0).Name   
            'Print the name of the log provider object located at position [0].  
            Console.WriteLine("The ID of the first event handler is: {0}", dtsEHFirstEnTry.ID)  
            Console.WriteLine("The Name of the first event handler is: {0}", nameOfFirstItem)  
        End Sub  
    End Class  
End Namespace  
示例输出:
可以使用项语法? True
第一个事件处理程序的 ID 为:{4B9E438E-BA17-4A51-8235-3072AFF92F99}
第一个事件处理程序的名称为:OnError
注解
如果对方法的 Contains 调用返回 true,则可以使用语法 DtsEventHandlers[index]访问集合中的指定元素。 
              Contains如果该方法返回false,此属性将引发异常。 在 C# 中,此属性是 DtsEventHandlers 类的索引器。