ConnectionInfos.Item[Object] Свойство

Определение

Возвращает объект ConnectionInfo из коллекции по имени, индексу, идентификатору или удостоверению.

public:
 property Microsoft::SqlServer::Dts::Runtime::ConnectionInfo ^ default[System::Object ^] { Microsoft::SqlServer::Dts::Runtime::ConnectionInfo ^ get(System::Object ^ index); };
public Microsoft.SqlServer.Dts.Runtime.ConnectionInfo this[object index] { get; }
member this.Item(obj) : Microsoft.SqlServer.Dts.Runtime.ConnectionInfo
Default Public ReadOnly Property Item(index As Object) As ConnectionInfo

Параметры

index
Object

Имя, индекс, идентификатор или удостоверение объекта, который необходимо вернуть из коллекции.

Значение свойства

Объект ConnectionInfo из коллекции, который соответствует имени, индексу, идентификатору или удостоверению, заданному в параметре index.

Примеры

В следующем примере кода извлекается элемент из коллекции с помощью двух методов. Первый метод использует connectionInfos[0] синтаксис для получения всего объекта, расположенного в первой позиции коллекции, а затем помещает его в connInfo объект. Теперь можно получить все свойства из ConnectionInfo объекта, как обычно. Второй метод извлекает определенное свойство из первого объекта в коллекции.

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

namespace ConnectionInfos_GetEnum  
{  
    class Program  
    {  
        static void Main(string[] args)  
        {  
            Application dtsApplication = new Application();  
            ConnectionInfos connectionInfos = dtsApplication.ConnectionInfos;  

            //Using the Item method syntax of [x], obtain the first entry and a name.  
            ConnectionInfo connInfo = connectionInfos[0];  
            String nameOfFirstItem = connectionInfos[0].Name;  

            //Print the name of the log provider object located at position [0].  
            Console.WriteLine("The ID of the first connection info is: {0}", connInfo.ID);  
            Console.WriteLine("The Name of the first connection info is: {0}", nameOfFirstItem);  

        }  
    }  
}  
Imports System  
Imports System.Collections.Generic  
Imports System.Text  
Imports Microsoft.SqlServer.Dts.Runtime  

Namespace ConnectionInfos_GetEnum  
    Class Program  
        Shared  Sub Main(ByVal args() As String)  
            Dim dtsApplication As Application =  New Application()   
            Dim connectionInfos As ConnectionInfos =  dtsApplication.ConnectionInfos   

            'Using the Item method syntax of [x], obtain the first entry and a name.  
            Dim connInfo As ConnectionInfo =  connectionInfos(0)   
            Dim nameOfFirstItem As String =  connectionInfos(0).Name   

            'Print the name of the log provider object located at position [0].  
            Console.WriteLine("The ID of the first connection info is: {0}", connInfo.ID)  
            Console.WriteLine("The Name of the first connection info is: {0}", nameOfFirstItem)  

        End Sub  
    End Class  
End Namespace  

Образец вывода:

The ID of the first connection info is: {41F5EFE4-E91A-4EB0-BF10-D40FD48B3C03}

The Name of the first connection info is: DTS Connection Manager for Files

Комментарии

Если вызов Contains метода возвращается true, доступ к указанному элементу в коллекции можно получить с помощью синтаксиса ConnectionInfos[index]. Contains Если метод возвращаетсяfalse, это свойство создает исключение. В C# это свойство является индексатором класса ConnectionInfos.

Применяется к