Short answer: It depends.
Longer answer: The purpose of LINQ is to allow the developer to express intent of a query without having to provide how the query will be performed. We can use the same query syntax for nearly anything that can be represented as a set.
For LINQ to Objects, it currently simply does what you described - a linear traversal of the sequence. Under the hood, LINQ can use an IQueryProvider
to defer the how to a more sophisticated implementation.
The provider's job is to turn the query (for example, Where(predicate)
) into actual executing code. For something like LINQ to SQL or LINQ to Entities in the Entity Framework, it translates the query into SQL and executes it.
So at a basic level, the idea is "it doesn't matter" how it works - it's supposed to help developers be more productive by writing queries more declaratively. But it is helpful to look up the documentation for the specific LINQ provider you're using, so you can understand how to most effectively leverage it.