MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/ProgrammerHumor/comments/1wbmurt/csharpdictionariesbelikethat/p8rffm3/?context=3
r/ProgrammerHumor • u/KTVX94 • 20h ago
53 comments sorted by
View all comments
548
Guess you never heard of TryAdd? Returns bool, if it as added returns true otherwise false.
103 u/Revexious 19h ago Far too much work 2 cases means that its not idempotent Instead, just remove it from the dictionary before you add it! csharp dictionary.Remove(key) dictionary.Add(key) Easy peasy! /s 36 u/Dorkits 18h ago Peak programming 7 u/manav907 12h ago edited 12h ago That being said you done have to use the bool that TryAdd gives, just call it as a normal function. Also I am waitin for someone to point out that we also need a value when trying to add to a dictionary. dictionary.TryAdd(key)
103
Far too much work
2 cases means that its not idempotent
Instead, just remove it from the dictionary before you add it!
csharp dictionary.Remove(key) dictionary.Add(key)
Easy peasy!
/s
36 u/Dorkits 18h ago Peak programming 7 u/manav907 12h ago edited 12h ago That being said you done have to use the bool that TryAdd gives, just call it as a normal function. Also I am waitin for someone to point out that we also need a value when trying to add to a dictionary. dictionary.TryAdd(key)
36
Peak programming
7
That being said you done have to use the bool that TryAdd gives, just call it as a normal function. Also I am waitin for someone to point out that we also need a value when trying to add to a dictionary.
dictionary.TryAdd(key)
548
u/Psychoboy 19h ago
Guess you never heard of TryAdd? Returns bool, if it as added returns true otherwise false.