Hello, there are two lists with domains, the first contains 1000 items, the second - 20,000; the essence of the question is this: it is necessary to determine whether the second list contains a specific element of the first list or not. And so you need to run through the entire collection of 1000 elements. Just going over cycles is not an option to make a LINQ request?

  • 2
    The answers offered to you contain good solutions: HashSet, sorting, parallelization. To give you a more specific answer, specify the type of your items and the type of collections used, and whether you can take other collections. - Alexander Petrov
  • Hello, thank you for the attention paid to my question. The type of elements is string, I think to use List <T>. The problem itself is in English: it is in the blacklist. This is not a loop. If I do 1000 lookups it's simply too slow. For example, if a.biz TLD is a blacklisted, it should be positive. On the other hand, b.biz should not match, because the sub-domain is different. - Melcon
  • Too slow - this is nonsense. Intersect on collections of size 1000 and 20,000 work out instantly. And in general, no one will do your homework for you. Show your solution attempts, provide your code. Indicate what the problem is. - Alexander Petrov

1 answer 1

Depends on what you pursue.

Performance

If you expect that LINQ will give you improved performance, this is nonsense.

LINQ transforms into foreach performance will be no more.

If domains are strings, then it is better to use HashSet<T> and subtract one set from another, the performance should be higher than that of regular lists.

Conciseness

For this purpose LINQ copes.

  • If there is no such thing in * .config: <UseRandomizedStringHashAlgorithm enabled = "1" /> - kimaman2