I need a list of strings and a way to quickly determine if a string is contained within that list.
To enhance lookup speed, I considered SortedList and Dictionary; however, both work with KeyValuePairs when all I need is a single string.
I know I could use a KeyValuePair and simply ignore the Value portion. But I do prefer to be efficient and am just wondering if there is a collection better suited to my requirements.
If you’re on .NET 3.5 or higher, use
HashSet<String>.Failing that, a
Dictionary<string, byte>(or whatever type you want for theTValuetype parameter) would be faster than aSortedListif you have a lot of entries – the latter will use a binary search, so it’ll be O(log n) lookup, instead of O(1).