c# - Dictionary TryGetValue without using value returned -
i'm implementing simple dictionary<string, int>
keeps track of picture files download, , renaming of files.
string
- original filename
int
- new filename
i read on trygetvalue
vs containskey
, came across this:
trygetvalue
approach fastercontainskey
approach when want check key in collection , want value associated it. if want check key present or not usecontainskey
only.
from here
as such, wondering other people's views on following:
should use trygetvalue
if not plan use returned value
, assuming dictonary size grow 1000 entries, , duplicate checks everytime download ie. frequently?
in theory, follow documentation. if don't want value use containskey
because there's no code go , grab value out of memory.
now, in practice, doesn't matter because you're micro-optimizing on dictionary
that's small in grand scheme of things. so, in practice, best , readability of code.
and idea, would grow 1000 entries
really small isn't going matter in practice.
Comments
Post a Comment