LoadTestContext.TryGetValue 方法

取得與指定之索引鍵相關聯的值。

命名空間:  Microsoft.VisualStudio.TestTools.LoadTesting
組件:  Microsoft.VisualStudio.QualityTools.LoadTestFramework (在 Microsoft.VisualStudio.QualityTools.LoadTestFramework.dll 中)

語法

'宣告
Public Function TryGetValue ( _
    key As String, _
    <OutAttribute> ByRef value As Object _
) As Boolean
public bool TryGetValue(
    string key,
    out Object value
)
public:
virtual bool TryGetValue(
    String^ key, 
    [OutAttribute] Object^% value
) sealed
abstract TryGetValue : 
        key:string * 
        value:Object byref -> bool 
override TryGetValue : 
        key:string * 
        value:Object byref -> bool 
public final function TryGetValue(
    key : String, 
    value : Object
) : boolean

參數

  • value
    型別:System.Object%
    參考的物件,這個物件會取得索引鍵 (如果找到的話) 的值,否則取得 value 參數之型別的預設值。這個參數可以未經初始化傳遞。

傳回值

型別:System.Boolean
如果它包含具有指定之 key 的項目,則為 true,否則為 false。

實作

IDictionary<TKey, TValue>.TryGetValue(TKey, TValue%)

例外狀況

例外狀況 條件
ArgumentNullException

key 為 nullnull 參考 (即 Visual Basic 中的 Nothing)。

備註

如果許多嘗試的索引鍵都不在字典中,這會是嘗試取得值的最有效方式。這個方法結合了 ContainsKey 方法的功能和 Item 屬性。

如果找不到 key,則 outvalue 參數會取得適當的預設值:整數型別 (Integer Type) 為零、布林值 (Boolean) 型別為 false、參考型別則為 nullnull 參考 (即 Visual Basic 中的 Nothing)。

.NET Framework 安全性

請參閱

參考

LoadTestContext 類別

Microsoft.VisualStudio.TestTools.LoadTesting 命名空間