6

I have a list of strings, I need to be able to simply probe if a new string is in the table or not. When the list is large, testing a simple list directly is pretty inefficient... so typically I use a Dictionary to get constant lookup speeds, although I don't actually care about the value. This seems like a misuse of a dictionary, so I'm wondering what other approaches I could take.

Is there a better way to do hit testing that I am unaware of?

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
tbischel
  • 6,337
  • 11
  • 51
  • 73
  • Duplicate: http://stackoverflow.com/questions/1860306/net-how-to-efficiently-check-for-uniqueness-in-a-liststring-of-50-000-items/1860311#1860311 – SLaks Dec 17 '09 at 02:15
  • Hit-testing means checking whether a point is inside of something. (eg, a circle or a control). – SLaks Dec 17 '09 at 02:17
  • 1
    I suppose I was thinking of something similar to a "cache hit" when I said hit-test – tbischel Dec 17 '09 at 02:21

2 Answers2

16

You should use a HashSet<string>, which is specifically designed for this purpose.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
1

A HashSet is better suited than a Dictionary, for this purpose.

Noon Silk
  • 54,084
  • 6
  • 88
  • 105