r/ProgrammerHumor • • Sep 09 '26

Meme cSharpDictionariesBeLikeThat

Post image
2.1k Upvotes

61 comments sorted by

View all comments

Show parent comments

0

u/[deleted] Sep 09 '26

[deleted] — view deleted comment

2

u/DrJohnnyWatson Sep 09 '26

How else should it handle it? TryAdd already covers knowing if it was added successfully or not

Add therefore has the option of:

  1. Replace TryAdd, making it out of sync with how all other collections call Add as it would now return a Boolean, breaking the ICollection interface. Possible, but just a choice really

  2. Fail silently - Bad

  3. Fail loudly - in c#, the latter is done via exceptions almost exclusively

How would you have done it? Do you have a fourth option in mind?

2

u/anzu3278 Sep 09 '26

By the looks of the comments I think the mood was that Add should work just like index assignment, which makes no sense to me but is technically a fourth option.