Condividi tramite


Language design choices and query comprehensions (by yag)

An interesting part of Project LINQ is the concept of Query Comprehensions. In essence, they allow you to perform a translation from a more declarative syntax to a more object based one. For instance the following internal LINQ syntax in C#:

   expr = names.Where(s => s.Length == 5).OrderBy(s => s).Select(s => s.ToUpper()) ;

which is chock full of lambda expressions (Where, OrderBy and Select), becomes legible as:

  (C#) expr = from s in names where s.Length == 5 orderby s select s.ToUpper() ;

  (VB) expr = select s.ToUpper() from s in names where s.Length = 5

The key here is that behind the scenes the code is the same, but each language can define its own comprehensions to make things easier for their customers. One question this raises is "which is better From...Select as in C#, or Select...From as VB has chosen"? Paul Vick gives both sides of the argument in this blog entry.

Comments

  • Anonymous
    September 26, 2005
    The "Comparing C# 3.0 and VB 9.0 LINQ Syntax" item at http://oakleafblog.blogspot.com/ compares the forthcoming VB 9.0 query comprehension operators with those for C# 3.0.