Convert C# statement body lambda to VB

后端 未结 2 643
小鲜肉
小鲜肉 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
      
    0 讨论(0)
  • 2021-01-22 02:03

    Could you make a new class that accepts the Form in the constructor and has chkSelectPanel as a field, allowing you to use instance methods as your event handlers?

    0 讨论(0)
提交回复
热议问题