问题描述:

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.

网友答案:

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 Function

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.

网友答案:

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

Use the Function keyword.

相关阅读:
Top