A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.dictionary-2.tryadd below:

Dictionary<TKey,TValue>.TryAdd(TKey, TValue) Method (System.Collections.Generic) | Microsoft Learn

Dictionary<TKey,TValue>.TryAdd(TKey, TValue) Method Definition

Attempts to add the specified key and value to the dictionary.

public:
 bool TryAdd(TKey key, TValue value);
public bool TryAdd(TKey key, TValue value);
member this.TryAdd : 'Key * 'Value -> bool
Public Function TryAdd (key As TKey, value As TValue) As Boolean
Parameters
key
TKey

The key of the element to add.

value
TValue

The value of the element to add. It can be null.

Returns

true if the key/value pair was added to the dictionary successfully; otherwise, false.

Exceptions Remarks

Unlike the Add method, this method doesn't throw an exception if the element with the given key exists in the dictionary. Unlike the Dictionary indexer, TryAdd doesn't override the element if the element with the given key exists in the dictionary. If the key already exists, TryAdd does nothing and returns false.

Collaborate with us on GitHub

The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide. In this article

Was this page helpful?


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4