Best Collection for Fast String Lookup

后端 未结 7 1672
别跟我提以往
别跟我提以往 2020-12-30 22:28

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

7条回答
  •  暖寄归人
    2020-12-30 22:48

    If you're on .NET 3.5 or higher, use HashSet.

    Failing that, a Dictionary (or whatever type you want for the TValue type parameter) would be faster than a SortedList if 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).

提交回复
热议问题