开发者

Unique set of strings in C#

开发者 https://www.devze.com 2022-12-14 01:25 出处:网络
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, te开发者_运维问答sting a simple list directly is pretty inefficient... so ty

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, te开发者_运维问答sting 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?


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消