DbConnectionStringBuilder.Keys Tulajdonság
Definíció
Fontos
Egyes információk olyan, kiadás előtti termékekre vonatkoznak, amelyek a kiadásig még jelentősen módosulhatnak. A Microsoft nem vállal kifejezett vagy törvényi garanciát az itt megjelenő információért.
ICollection Lekéri azokat a kulcsokat, amelyek a 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
Tulajdonság értéke
Olyan ICollection , amely tartalmazza a kulcsokat a DbConnectionStringBuilder.
Megvalósítás
- Attribútumok
Példák
Az alábbi konzolalkalmazás-példa létrehoz egy újat DbConnectionStringBuilder, és hozzáad néhány kulcsot. A kód végighalad a ICollectionKeys kulcs/érték párokat megjelenítő tulajdonság által visszaadott értéken, majd hozzáad egy új kulcsot. Mivel a Keys tulajdonság dinamikus ICollectionértéket ad vissza, a második ciklus megjeleníti az összes kulcs-érték párot, beleértve a legújabb elemet is.
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
Megjegyzések
A benne lévő ICollection értékek sorrendje meghatározatlan, de megegyezik a tulajdonság által ICollection visszaadott társított értékekkelValues.
A visszaadott ICollection példány nem statikus másolat, hanem az ICollection eredeti DbConnectionStringBuilderkulcsokra hivatkozik. Ezért a változások a DbConnectionStringBuilderICollection.