DbConnectionStringBuilder.Keys 속성

정의

ICollection의 키를 포함하는 DbConnectionStringBuilder을 가져옵니다.

public:
 virtual property System::Collections::ICollection ^ Keys { System::Collections::ICollection ^ get(); };
public virtual System.Collections.ICollection Keys { get; }
[System.ComponentModel.Browsable(false)]
public virtual System.Collections.ICollection Keys { get; }
member this.Keys : System.Collections.ICollection
[<System.ComponentModel.Browsable(false)>]
member this.Keys : System.Collections.ICollection
Public Overridable ReadOnly Property Keys As ICollection

속성 값

ICollection의 키를 포함하는 DbConnectionStringBuilder입니다.

구현

특성

예제

다음 콘솔 애플리케이션 예제에서는 새 DbConnectionStringBuilder, 일부 키를 추가 합니다. 코드는 키/값 쌍을 표시하는 속성에서 Keys 반환된 를 반복 ICollection 한 다음 새 키를 추가합니다. 속성은 Keys 동적 ICollection를 반환하므로 두 번째 루프는 최신 항목을 포함한 모든 키/값 쌍을 표시합니다.

static void Main()
{
    DbConnectionStringBuilder builder = new
        DbConnectionStringBuilder();
    builder["Data Source"] = "(local)";
    builder["Integrated Security"] = true;
    builder["Initial Catalog"] = "AdventureWorks";

    // Obtain reference to the collection of keys.
    ICollection keys = builder.Keys;

    Console.WriteLine("Keys before adding TimeOut:");
    foreach (string key in keys)
        Console.WriteLine("{0}={1}", key, builder[key]);

    // Add a new item to the collection.
    builder["Timeout"] = 300;

    Console.WriteLine();
    Console.WriteLine("Keys after adding TimeOut:");

    // Because the Keys property is dynamically updated,
    // the following loop includes the Timeout key.
    foreach (string key in keys)
        Console.WriteLine("{0}={1}", key, builder[key]);
    Console.WriteLine();
    Console.WriteLine("Press Enter to continue.");
    Console.ReadLine();
}
Sub Main()
    Dim builder As New DbConnectionStringBuilder
    builder("Data Source") = "(local)"
    builder("integrated security") = True
    builder("Initial Catalog") = "AdventureWorks;NewValue=Bad"

    ' Obtain reference to the collection of keys.
    Dim keys As ICollection = builder.Keys

    Console.WriteLine("Keys before adding TimeOut:")
    For Each key As String In keys
        Console.WriteLine("{0}={1}", key, builder(key))
    Next

    ' Add a new item to the collection.
    builder("Timeout") = 300

    Console.WriteLine()
    Console.WriteLine("Keys after adding TimeOut:")

    ' Because the Keys property is dynamically updated, 
    ' the following loop includes the Timeout key.
    For Each key As String In keys
        Console.WriteLine("{0}={1}", key, builder(key))
    Next

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

설명

ICollection에서 값의 순서는 지정되지 않지만 ICollection 속성이 반환하는 Values의 연결된 값과 순서가 동일합니다.

반환 ICollection 된 는 정적 복사본이 아니며, 대신 는 ICollection 원래 DbConnectionStringBuilder의 키를 다시 참조합니다. 따라서 에 대한 DbConnectionStringBuilder 변경 내용은 에 ICollection반영됩니다.

적용 대상

추가 정보