Why can't select come first in a LINQ query?

What is the reason behind this restriction?

I believe the primary reason was actually Intellisense. Until an IDE knows what sort of collection you're using, it can't suggest which properties you want to use from the elements of that collection. The way the syntax works now, by the time you're writing a select or where clause, the IDE can tell what the element type is and make suggestions.

I would say it also has the benefit of making a lot more sense by putting the query in chronological order: you start with a source, filter it, transform it etc and end up with a result.

Finally, I suspect it makes the language transform from query expressions into "normal" C# (typically using extensions methods) simpler to express.

I think it would be more reasonable to ask why SQL is expressed backwards :)


I think it is because this in fact makes more sense. You first need to tell where to get it from before you tell what. I never understood the logic in SQL actually.

It also helps IntelliSense to show the appropriate fields and properties on the objects you are querying.

Tags:

C#

Linq