Query syntax in VB

Don Box's Spoutlet

Syndication

One other feature I'm liking in VB is that you can omit the trailing select clause in a query.

That is, you can simply say this:

From ch In "Hello" Where ch <> "H"

which in C# would look like this:

from ch in "Hello" where ch != 'H' select ch


Posted Nov 11 2007, 10:44 PM by don-box

Comments

Derek wrote re: Query syntax in VB
on 11-12-2007 8:21 AM
For short expression sequences like this, I almost always use the more compact extension method syntax (in C#).

"Hello".Where(c => c != 'H');
Anonymous wrote re: Query syntax in VB
on 11-14-2007 4:22 PM
In VB that's just this:
"Hello".Where(Function(c) c <> "H")
Jared wrote re: Query syntax in VB
on 11-27-2007 7:37 AM
In the VB query you may want to change "H" to "H"c to get a character comparison vs a conversion and string comparison.

Add a Comment

(required)  
(optional)
(required)  
Remember Me?