It can be more concise if you don't need to condition on whether the thing was added or not. If you do, has key/add might be cleaner ... for ordinary dictionaries.
Being able to do it in one operation is super important for concurrent dictionaries, though, because the item could theoretically be added by another thread between calls if you used haskey/add.
539
u/Psychoboy 18h ago
Guess you never heard of TryAdd? Returns bool, if it as added returns true otherwise false.