Posts Tagged ‘lambda’

VB.Net and lambda

November 30th, 2011

Using the terse lambda syntax used in C# also in VB.Net is also (almost) possible.

Here is a short example:

var nameList =
 myFacade.GetData().
 where( x => x.ID = 42 ).
 select( x => x.Name ).
 ToList();

which in VBNet becomes:

Dim nameList =
 myFacade.GetData().
 Where( Function(x) x.ID = 42 ).
 Select( Function(x) x.Name ).
 ToList()

Note that the periods have to be at the end of the line, otherwise the multi line capability of Vbnet doesn’t work.  This can be remedied by the old trailing underscore of VB.

If you need to set the type of x it is also doable:

Dim nameList =
 myFacade.GetData().
 Where( Function(x As MyClass) x.ID = 42 ).
 Select( Function(x As MyClass) x.Name ).
 ToList()

CompulsoryCat 1.1

October 21st, 2010

Just released version 1.1 of CompulsoryCat on google code.

It is a helper lib for getting the names of methods, classes, properties and other stuff out of the methods, classes etc.  It uses lambda or reflection to be as safe as possible.

It is unit tested and has a small exe to show a few examples of its use.  There is also a help file.