DbConnectionStringBuilder.Item[String] 속성

정의

지정된 키에 연결된 값을 가져오거나 설정합니다.

public:
 virtual property System::Object ^ default[System::String ^] { System::Object ^ get(System::String ^ keyword); void set(System::String ^ keyword, System::Object ^ value); };
public virtual object this[string keyword] { get; set; }
[System.ComponentModel.Browsable(false)]
public virtual object this[string keyword] { get; set; }
member this.Item(string) : obj with get, set
[<System.ComponentModel.Browsable(false)>]
member this.Item(string) : obj with get, set
Default Public Overridable Property Item(keyword As String) As Object

매개 변수

keyword
String

가져오거나 설정할 항목의 키입니다.

속성 값

지정한 키와 연결된 값입니다. 지정한 키가 없는 경우 해당 키를 가져오려고 시도하면 null 참조(Visual Basic의Nothing )가 반환되고 해당 키를 설정하려고 시도하면 지정한 키를 사용하여 새 요소가 만들어집니다.

null(Visual Basic의Nothing ) 키를 전달하면 ArgumentNullException이 throw됩니다. null 값을 할당하면 키/값 쌍이 제거됩니다.

특성

예외

keyword이 null 참조(Visual Basic의 경우 Nothing)인 경우

속성이 설정되어 있으며 DbConnectionStringBuilder 가 읽기 전용입니다.

또는

속성이 설정되어 있고 keyword가 컬렉션에 없으며 DbConnectionStringBuilder의 크기가 고정된 경우

예제

다음 콘솔 애플리케이션을 만듭니다 DbConnectionStringBuilder 해당 연결에 키/값 쌍을 추가 하 고 문자열을 사용 하 여는 Item[] 속성입니다.

static void Main()
{
    DbConnectionStringBuilder builder = new
        DbConnectionStringBuilder();
    builder["Data Source"] = "(local)";

    // Note that Item is the indexer, so
    // you do not include it in the reference.
    builder["integrated security"] = true;
    builder["Initial Catalog"] = "AdventureWorks";

    // Overwrite the existing value for the Data Source key,
    // because it already exists within the collection.
    builder["Data Source"] = ".";

    Console.WriteLine(builder.ConnectionString);
    Console.WriteLine();
    Console.WriteLine("Press Enter to continue.");
    Console.ReadLine();
}
Module Module1

    Sub Main()
        Dim builder As New DbConnectionStringBuilder
        builder.Item("Data Source") = "(local)"

        ' Item is the default property, so 
        ' you need not include it in the reference.
        builder("integrated security") = True
        builder.Item("Initial Catalog") = "AdventureWorks"

        ' Overwrite the existing value for the data source value, 
        ' because it already exists within the collection.
        builder.Item("Data Source") = "."

        Console.WriteLine(builder.ConnectionString)
        Console.WriteLine()
        Console.WriteLine("Press Enter to continue.")
        Console.ReadLine()
    End Sub

설명

이 속성을 설정하면 지정된 키가 사전에 이미 있으면 값이 바뀝니다. 그렇지 않으면 새 요소가 만들어집니다.

적용 대상

추가 정보