CollectionExtensions.TryAdd<TKey,TValue> 方法
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
嘗試將指定的 key
和 value
新增至 dictionary
。
public:
generic <typename TKey, typename TValue>
[System::Runtime::CompilerServices::Extension]
static bool TryAdd(System::Collections::Generic::IDictionary<TKey, TValue> ^ dictionary, TKey key, TValue value);
C#
public static bool TryAdd<TKey,TValue> (this System.Collections.Generic.IDictionary<TKey,TValue> dictionary, TKey key, TValue value);
static member TryAdd : System.Collections.Generic.IDictionary<'Key, 'Value> * 'Key * 'Value -> bool
<Extension()>
Public Function TryAdd(Of TKey, TValue) (dictionary As IDictionary(Of TKey, TValue), key As TKey, value As TValue) As Boolean
- TKey
字典中的索引鍵類型。
- TValue
字典中的值類型。
- dictionary
- IDictionary<TKey,TValue>
具有 TKey
類型索引鍵和 TValue
類型值的字典。
- key
- TKey
要新增的值索引鍵。
- value
- TValue
要加入的值。
當 key
和 value
成功新增至 dictionary
時,為 true
;當 dictionary
已包含指定的 key
時 (在此狀況下不新增任何項目),則為 false
。
dictionary
為 null
。
產品 | 版本 |
---|---|
.NET | Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Standard | 2.1 |