Bagikan melalui


DbConnectionStringBuilder.Keys Properti

Definisi

ICollection Mendapatkan yang berisi kunci di 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

Nilai Properti

Yang ICollection berisi kunci di DbConnectionStringBuilder.

Penerapan

Atribut

Contoh

Contoh aplikasi konsol berikut membuat baru DbConnectionStringBuilder, dan menambahkan beberapa kunci. Kode mengulang melalui ICollection yang dikembalikan oleh properti yang Keys menampilkan pasangan kunci/nilai, lalu menambahkan kunci baru. Keys Karena properti mengembalikan dinamis ICollection, perulangan kedua menampilkan semua pasangan kunci/nilai, termasuk item terbaru.

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

Keterangan

Urutan nilai dalam ICollection tidak ditentukan, tetapi urutannya sama dengan nilai terkait dalam yang ICollection dikembalikan oleh Values properti .

yang dikembalikan ICollection bukan salinan statis; sebaliknya, ICollection mengacu kembali ke kunci di aslinya DbConnectionStringBuilder. Oleh karena itu, perubahan pada DbConnectionStringBuilder tercermin dalam ICollection.

Berlaku untuk

Lihat juga