I have a list of about 500 strings "joe" "john" "jack" ... "jan"
I only need to find the ordinal.
In my example, the list will never be changed.
One could just put them in a list and IndexOf
ll.Add("joe") ll.Add("john") ... ll.Add("jan") ll.IndexOf("jib") is 315 or you can put them in a dictionary, using the ordinal integers as the values,
dd.Add("joe", 1) dd.Add("john", 2) dd.Add("jack", 3) ... dd.Add("jan", 571) dd["jib"] is 315 FTR the strings are 3 to 8 characters long. FTR this is in a Unity, hence Mono, milieu.
- Purely for performance, is one approach generally preferable?
1b) Indeed, I found a number of analysis of this nature: http://www.dotnetperls.com/dictionary-time (google for a number of similar analyses). Does this apply to the situation I describe or am I off here?
Regarding which is better in a general development engineering sense. (Completely set aside performance.) It seems to me both have obvious advantages and disadvantages; neither is very elegant.
It's a shame there isn't a "HashSetLikeThingWithOrdinality" type of facility - if I'm missing an obvious please let us know. Indeed, this seems like a fairly common, basic, collections use case - "get the ordinal of some strings" - perhaps I am completely missing something obvious.
It's a shame there isn't a "HashSetLikeThingWithOrdinality" type of facility - if I'm missing an obvious please let us know. Indeed, this seems like a fairly common, basic, collections use case - "get the ordinal of some strings" - perhaps I am completely missing something obvious.