DbConnectionStringBuilder.Keys Propriété

Définition

Obtient un ICollection qui contient les clés de DbConnectionStringBuilder.Gets an ICollection that contains the keys in the DbConnectionStringBuilder.

public:
 virtual property System::Collections::ICollection ^ Keys { System::Collections::ICollection ^ get(); };
[System.ComponentModel.Browsable(false)]
public virtual System.Collections.ICollection Keys { get; }
member this.Keys : System.Collections.ICollection
Public Overridable ReadOnly Property Keys As ICollection

Valeur de propriété

ICollection qui contient les clés de DbConnectionStringBuilder.An ICollection that contains the keys in the DbConnectionStringBuilder.

Implémente

Attributs

Exemples

L’exemple d’application console suivant crée un DbConnectionStringBuildernouveau et ajoute des clés.The following console application example creates a new DbConnectionStringBuilder, and adds some keys. Le code parcourt ICollection le retourné par Keys la propriété qui affiche les paires clé/valeur, puis ajoute une nouvelle clé.The code loops through the ICollection returned by the Keys property displaying the key/value pairs, and then adds a new key. Étant donné Keys que la propriété retourne ICollectionune dynamique, la deuxième boucle affiche toutes les paires clé/valeur, y compris l’élément le plus récent.Because the Keys property returns a dynamic ICollection, the second loop displays all the key/value pairs, including the newest 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

Remarques

L'ordre des valeurs dans ICollection n'est pas spécifié, mais correspond à celui des valeurs associées dans l'objet ICollection retourné par la propriété Values.The order of the values in the ICollection is unspecified, but it is the same order as the associated values in the ICollection returned by the Values property.

Le retourné ICollection n’est pas une copie statique ; à la ICollection place, fait référence aux clés dans le DbConnectionStringBuilderd’origine.The returned ICollection is not a static copy; instead, the ICollection refers back to the keys in the original DbConnectionStringBuilder. Par conséquent, les modifications DbConnectionStringBuilder apportées à ICollectionsont reflétées dans le.Therefore, changes to the DbConnectionStringBuilder are reflected in the ICollection.

S’applique à

Voir aussi