共用方式為


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,並新增一些鍵。 程式碼會迴圈顯示 ICollection 鍵值對的 return Properties Keys ,然後新增鍵。 由於屬性 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值的順序未明確說明,但與屬性回傳Values的相關值ICollection順序相同。

返回 ICollection 的 不是靜態副本;而是 ICollection 回溯到原始 DbConnectionStringBuilder的金鑰。 因此,對 的 DbConnectionStringBuilder 變化會反映在 ICollection中。

適用於

另請參閱