DbConnectionStringBuilder.Keys Eigenschap
Definitie
Belangrijk
Bepaalde informatie heeft betrekking op een voorlopige productversie die aanzienlijk kan worden gewijzigd voordat deze wordt uitgebracht. Microsoft biedt geen enkele expliciete of impliciete garanties met betrekking tot de informatie die hier wordt verstrekt.
Hiermee haalt u een ICollection op met de sleutels in de 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
Waarde van eigenschap
Een ICollection met de sleutels in de DbConnectionStringBuilder.
Implementeringen
- Kenmerken
Voorbeelden
In het volgende consoletoepassingsvoorbeeld wordt een nieuwe DbConnectionStringBuildergemaakt en worden enkele sleutels toegevoegd. De code doorloopt de ICollection geretourneerde eigenschap Keys die de sleutel-waardeparen weergeeft en voegt vervolgens een nieuwe sleutel toe. Omdat de Keys eigenschap een dynamische ICollectionwaarde retourneert, geeft de tweede lus alle sleutel-/waardeparen weer, inclusief het nieuwste item.
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
Opmerkingen
De volgorde van de waarden in de ICollection eigenschap is niet opgegeven, maar het is dezelfde volgorde als de bijbehorende waarden in de ICollection geretourneerde Values eigenschap.
Het geretourneerde ICollection is geen statische kopie. In plaats daarvan verwijst de ICollection waarde terug naar de sleutels in het origineel DbConnectionStringBuilder. Daarom worden wijzigingen in ICollectionde DbConnectionStringBuilder .