High performance “contains” search in list of strings in C#

前端 未结 7 1650
情话喂你
情话喂你 2020-12-05 07:54

I have a list of approx. 500,000 strings, each approx. 100 characters long. Given a search term, I want to identify all strings in the list that contain the search term. At

7条回答
  •  忘掉有多难
    2020-12-05 08:42

    Have you tried the following?

    list.FindAll(x => x.Contains("YourTerm")).ToList();
    

    For some reason the List.AsParallel().Where(...) is slower than list.FindAll(...) on my PC.

    list.AsParallel().Where(x => x.Contains("YourTerm")).ToList();
    

    Hope this will help you.

提交回复
热议问题