DbConnectionStringBuilder.Item[String] Vlastnost

Definice

Získá nebo nastaví hodnotu přidruženou k zadanému klíči.

public:
 virtual property System::Object ^ default[System::String ^] { System::Object ^ get(System::String ^ keyword); void set(System::String ^ keyword, System::Object ^ value); };
public virtual object this[string keyword] { get; set; }
[System.ComponentModel.Browsable(false)]
public virtual object this[string keyword] { get; set; }
member this.Item(string) : obj with get, set
[<System.ComponentModel.Browsable(false)>]
member this.Item(string) : obj with get, set
Default Public Overridable Property Item(keyword As String) As Object

Parametry

keyword
String

Klíč položky, kterou chcete získat nebo nastavit.

Hodnota vlastnosti

Hodnota přidružená k zadanému klíči. Pokud zadaný klíč nebyl nalezen, pokus o získání vrátí nulový odkaz (Nothing v jazyce Visual Basic) a pokus o nastavení vytvoří nový prvek pomocí zadaného klíče.

Předání klíče null (Nothing v jazyce Visual Basic) vyvolá .ArgumentNullException Přiřazení hodnoty null odebere dvojici klíč-hodnota.

Atributy

Výjimky

keyword je odkaz s hodnotou null (Nothing v jazyce Visual Basic).

Vlastnost je nastavená a DbConnectionStringBuilder je jen pro čtení.

-nebo-

Vlastnost je nastavená, keyword v kolekci neexistuje a DbConnectionStringBuilder má pevnou velikost.

Příklady

Následující konzolová aplikace vytvoří novou DbConnectionStringBuilder a přidá páry klíč/hodnota do připojovacího Item[] řetězce pomocí vlastnosti .

static void Main()
{
    DbConnectionStringBuilder builder = new
        DbConnectionStringBuilder();
    builder["Data Source"] = "(local)";

    // Note that Item is the indexer, so
    // you do not include it in the reference.
    builder["integrated security"] = true;
    builder["Initial Catalog"] = "AdventureWorks";

    // Overwrite the existing value for the Data Source key,
    // because it already exists within the collection.
    builder["Data Source"] = ".";

    Console.WriteLine(builder.ConnectionString);
    Console.WriteLine();
    Console.WriteLine("Press Enter to continue.");
    Console.ReadLine();
}
Module Module1

    Sub Main()
        Dim builder As New DbConnectionStringBuilder
        builder.Item("Data Source") = "(local)"

        ' Item is the default property, so 
        ' you need not include it in the reference.
        builder("integrated security") = True
        builder.Item("Initial Catalog") = "AdventureWorks"

        ' Overwrite the existing value for the data source value, 
        ' because it already exists within the collection.
        builder.Item("Data Source") = "."

        Console.WriteLine(builder.ConnectionString)
        Console.WriteLine()
        Console.WriteLine("Press Enter to continue.")
        Console.ReadLine()
    End Sub

Poznámky

Při nastavení této vlastnosti, pokud zadaný klíč již existuje ve slovníku, je hodnota nahrazena; v opačném případě se vytvoří nový prvek.

Platí pro

Viz také