tags:

views:

75

answers:

2

Of the 51 Standard Query Operators (of which only 42 are actually query operators), only 24 are directly supported by Visual Basic 9 and just 11 by C# 3: Query Expression Syntax for Standard Query Operators.

In many cases, query syntax is arguably more readable than the equivalent method syntax, especially when transparent identifiers are involved. However, that readability breaks down if you have to combine queries and method calls.

So the question: What query operators, current or hypothetical, would you like to have your language of choice support in query expression syntax?

A: 

I would love to have a use keyword that behaves like its namesake binding in F#, disposing the value assigned to it when appropriate:

var lengths = from path in myFiles
              use fs = File.OpenRead(path)
              select new { path, fs.Length };

(I know there are other ways to get the file length, just use your imagination.)

A workaround is described here: Using IDisposables with LINQ

dahlbyk
A: 

I've not tried it but can you make use of let?

var lengths = from path in myFiles
              let fs = File.OpenRead(path)
              select new { path, fs.Length };
Stephen Newman
use would essentially be an IDisposable-aware version of let. To see why it's necessary, consider how you would call Dispose() on each FileStream that your query would open.
dahlbyk
Yes, an IDisposable-aware version of let would be great. I'm not aware of anything that at the moment and it would be superb for this type of operation.
Stephen Newman