METHOD
Dictionary.TryAdd
Adds only when the key is absent; false leaves an existing value unchanged.
Formal Syntax & Structure
csharp syntaxcsharp
bool TryAdd(TKey key, TValue value)Working Example
Example Snippetcsharp
using System.Collections.Generic;var map = new Dictionary<int,string> { [1] = "old" };System.Console.WriteLine(map.TryAdd(1, "new"));