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 |