tags:

views:

664

answers:

2

Is it possible to create anonymous delegates in vb.net version 8 or earlier? If so, could someone provide an example of the syntax? Thanks.

+4  A: 

In VB 9.0 you can create single line lambda expressions

Dim del = Function (x) x + 42

In VB 10.0 (not yet released). You will be able to create both multiline function and sub routines (as well as single line subs). For example

Dim del = Function (x)
            Return x + 42
          End Funtion

EDIT OP clarified it was for pre- VB 9.0

No, there is no way prior to VB 9.0 to create lambda expressions / anonymous delegates in VB.

JaredPar
Although it didn't answer the question, thanks for the info about VB10 anonymous delegates!
Meta-Knight
+2  A: 

Yes, but only in Visual Studio 2008/.Net 3.0 and later.

Use the Function keyword.

Joel Coehoorn