SqlConnectionStringBuilder.Keys Property

Definition

获取包含 ICollection 中的键的 SqlConnectionStringBuilderGets an ICollection that contains the keys in the SqlConnectionStringBuilder.

public:
 virtual property System::Collections::ICollection ^ Keys { System::Collections::ICollection ^ get(); };
public override System.Collections.ICollection Keys { get; }
member this.Keys : System.Collections.ICollection
Public Overrides ReadOnly Property Keys As ICollection

Property Value

ICollection

一个 ICollection,它包含 SqlConnectionStringBuilder 中的键。An ICollection that contains the keys in the SqlConnectionStringBuilder.

Examples

以下控制台应用程序示例新建一个 SqlConnectionStringBuilderThe following console application example creates a new SqlConnectionStringBuilder. 该代码循环访问显示键/值对的 ICollection 属性返回的 KeysThe code loops through the ICollection returned by the Keys property displaying the key/value pairs.

using System.Data.SqlClient;

class Program
{
    static void Main()
    {
        SqlConnectionStringBuilder builder =
            new SqlConnectionStringBuilder();
        builder.DataSource = "(local)";
        builder.IntegratedSecurity = true;
        builder.InitialCatalog = "AdventureWorks";

        // Loop through the collection of keys, displaying
        // the key and value for each item:
        foreach (string key in builder.Keys)
            Console.WriteLine("{0}={1}", key, builder[key]);

        Console.WriteLine();
        Console.WriteLine("Press Enter to continue.");
        Console.ReadLine();
    }
}
Imports System.Data.SqlClient

Module Module1
    Sub Main()
        Dim builder As New SqlConnectionStringBuilder
        builder.DataSource = "(local)"
        builder.IntegratedSecurity = True
        builder.InitialCatalog = "AdventureWorks"

        ' Loop through the collection of keys, displaying 
        ' the key and value for each item.
        For Each key As String In builder.Keys
            Console.WriteLine("{0}={1}", key, builder(key))
        Next

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

Remarks

ICollection 中的值的顺序未指定,但与 ICollection 属性返回的 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.

Applies to

See also