OracleConnectionStringBuilder.ContainsKey(String) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
确定 OracleConnectionStringBuilder 是否包含特定键。
public:
override bool ContainsKey(System::String ^ keyword);
public override bool ContainsKey (string keyword);
override this.ContainsKey : string -> bool
Public Overrides Function ContainsKey (keyword As String) As Boolean
参数
- keyword
- String
要在 OracleConnectionStringBuilder 中定位的键。
返回
如果 OracleConnectionStringBuilder 包含具有指定键的元素,则为 true
;否则为 false
。
例外
keyword
为 Null(在 Visual Basic 中为 Nothing
)
示例
以下示例创建一个 OracleConnectionStringBuilder 实例,设置其一些属性,然后尝试通过调用 ContainsKey 方法来确定对象中是否存在各种键。
OracleConnectionStringBuilder builder =
new(GetConnectionString());
Console.WriteLine($"Connection string = '{builder.ConnectionString}'");
// Keys you've provided return true.
Console.WriteLine(builder.ContainsKey("Integrated Security"));
// Keys that are valid but have not been set return true.
Console.WriteLine(builder.ContainsKey("Unicode"));
// Keys that do not exist return false.
Console.WriteLine(builder.ContainsKey("MyKey"));
Sub Main()
Dim builder As _
New OracleConnectionStringBuilder(GetConnectionString())
Console.WriteLine("Connection string = " & builder.ConnectionString)
' Keys you have provided return true.
Console.WriteLine(builder.ContainsKey("Integrated Security"))
' Keys that are valid but have not been set return true.
Console.WriteLine(builder.ContainsKey("Unicode"))
' Keys that don't exist return false.
Console.WriteLine(builder.ContainsKey("MyKey"))
Console.WriteLine("Press Enter to continue.")
Console.ReadLine()
End Sub
Private Function GetConnectionString() As String
' To avoid storing the connection string in your code,
' you can retrieve it from a configuration file.
Return "Server=OracleDemo;Integrated Security=True"
End Function
注解
由于 OracleConnectionStringBuilder 包含固定大小的键/值对集合,因此 ContainsKey 方法只确定特定键名是否有效。