DbConnectionStringBuilder.Keys Egenskap
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Hämtar en ICollection som innehåller nycklarna i 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
Egenskapsvärde
En ICollection som innehåller nycklarna i DbConnectionStringBuilder.
Implementeringar
- Attribut
Exempel
I följande konsolprogramexempel skapas en ny DbConnectionStringBuilderoch vissa nycklar läggs till. Koden loopar igenom den ICollection som returneras av Keys egenskapen som visar nyckel/värde-paren och lägger sedan till en ny nyckel. Eftersom egenskapen Keys returnerar en dynamisk ICollectionvisar den andra loopen alla nyckel/värde-par, inklusive det senaste objektet.
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
Kommentarer
Ordningen på värdena i ICollection är ospecificerad, men det är samma ordning som de associerade värdena i den ICollection som returneras av Values egenskapen.
Den returnerade ICollection är inte en statisk kopia. I stället ICollection refererar den tillbaka till nycklarna i den ursprungliga DbConnectionStringBuilder. Därför återspeglas ändringarna DbConnectionStringBuilder i ICollection.