Convert C# statement body lambda to VB

后端 未结 2 642
小鲜肉
小鲜肉 2021-01-22 01:01

It appears that VB in VS8 doesn\'t support/convert lambda expressions with a statement body. I\'m using them in my C# application, but now must convert it to VB.

I\'m c

2条回答
  •  被撕碎了的回忆
    2021-01-22 01:50

    Wait for the nearest release of .NET 4, it will support things like this in VB. Don't see other alternative.

    Ugly alternatives are:

    1. This work, but you can use a single statement in a function.

      AddHandler Me.Click, Function(o, e) MessageBox.Show("text")
      
    2. Create some regular Sub Foo

      Public Sub Foo(ByVal o As Object, ByVal e As EventArgs)
           MessageBox.Show("text")
      End Sub
      

      and use AddHandler to bind it to an event

      AddHandler Me.Click, AddressOf Foo
      

提交回复
热议问题