DbConnectionStringBuilder.Keys プロパティ
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
DbConnectionStringBuilder内のキーを含むICollectionを取得します。
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
プロパティ値
DbConnectionStringBuilder内のキーを含むICollection。
実装
- 属性
例
次のコンソール アプリケーションの例では、新しい DbConnectionStringBuilderを作成し、いくつかのキーを追加します。 コードは、キーと値のペアを表示するKeys プロパティによって返されるICollectionをループ処理し、新しいキーを追加します。 Keys プロパティは動的なICollectionを返すので、2 番目のループでは、最新の項目を含むすべてのキーと値のペアが表示されます。
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
注釈
ICollection内の値の順序は指定されていませんが、Values プロパティによって返されるICollection内の関連する値と同じ順序です。
返された ICollection は静的コピーではありません。代わりに、 ICollection は元の DbConnectionStringBuilderのキーを参照します。 そのため、 DbConnectionStringBuilder への変更は ICollectionに反映されます。