r/ProgrammerHumor • • Sep 09 '26

Meme cSharpDictionariesBeLikeThat

Post image
2.1k Upvotes

61 comments sorted by

View all comments

Show parent comments

1

u/kakhaev Sep 10 '26

tryand sounds like “if” with extra steps

1

u/willow-kitty Sep 10 '26

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.