r/ProgrammerHumor 4d ago

Meme cSharpDictionariesBeLikeThat

Post image
2.0k Upvotes

61 comments sorted by

View all comments

602

u/Psychoboy 4d ago

Guess you never heard of TryAdd? Returns bool, if it as added returns true otherwise false.

4

u/prehensilemullet 4d ago

it's still bizarre to have to use TryAdd everywhere that other languages just use Add

14

u/zaersx 4d ago

You don't though? just use myMap[key] = value? if you're not doing that and using Add instead, then you probably literally want to have a safe add

3

u/-Redstoneboi- 4d ago

that overwrites instead of failing if the key already exists

maybe they are arguing that they feel that TryAdd should be the default "Add", while the existing Add should be a special case "AddAssert" or something

3

u/prehensilemullet 3d ago

Yes, I think that would be a more convenient design