search List<string> for string .StartsWith()
c#, list, performance, string
Solution
1500 is usually too few:
you could search it in parallel with a simple divide and conquer of the problem. Search each half of the list in two (or divide into three, four, ..., parts) different jobs/threads.
Or store the strings in a (not binary) tree instead. Will be O(log n).
sorted in alphabetical order you can do a binary search (sort of the same as the previous one)
Problem
I have a ``` List<string> ``` with 1500 strings. I am now using the following code to pull out only string that start with the string prefixText. ``` foreach(string a in <MYLIST>) { if(a.StartsWith(prefixText, true, null)) { newlist.Add(a); } } ``` This is pretty fast, but I'm looking for google fast. Now my question is if I arrange the List in alphabetical order, then compare char by char can I make this faster? Or any other suggestions on making this faster?