I used Linq for some collection objects (Dictionary, List). Therefore, if I want to select items based on criteria, I write a Linq query and then list the linq object. So my question is, does Linq eliminate looping of the main collection and, as a result, improve performance?
Absolutely not. LINQ to Objects loops inside - how else could it work?
LINQ, on the other hand, is more efficient than some approaches you could take by streaming data only when it was needed, etc.
, ( ..), .
. LINQ () .
, , .
, , LINQ to SQL, , LINQ ado.net.
linq . , linq, "", IEnumerable . , , List , .
When you use the query directly, you still loop through the entire collection. You just don’t see everything, because the query will only return elements matching your filter. Overall performance will probably even be a hit, simply because of all the nested iterators that are involved. When you called ToList () in the query results and then used this result several times, then you would be better in terms of performance.