I need help converting a c# anonymous method to vb.net

前端 未结 3 1755
清歌不尽
清歌不尽 2020-12-21 12:08
provider.OptionsSet += delegate
{
  provider.FinishedLoading();
};
3条回答
  •  醉话见心
    2020-12-21 13:02

    Nice demonstration how converters get this dramatically wrong, they have for a long time. The += operator isn't VB.NET syntax, AddHandler is required to subscribe events. Where the Do comes from is anybody's guess. The lambda can't be a Function, except for the very rare cases where the delegate type returns a value. Three bugs in one line, you don't stand a chance. You need VS2010 to write a Sub lambda. Like this:

    Module Module1
        Sub Main()
            Dim obj As New Test
            AddHandler obj.example, Sub(sender As Object, e As EventArgs)
                                        '' etc...
                                    End Sub
        End Sub
    End Module
    
    Class Test
        Public Event example As EventHandler
    End Class
    

    For earlier versions, you'll need a little non-anonymous helper method. Like this:

        AddHandler obj.example, AddressOf helper
    ...
    Sub helper(ByVal sender As Object, ByVal e As EventArgs)
        '' etc..
    End Sub
    

    Human 1, machine 0.

提交回复
热议问题