我需要帮助将 c# 匿名方法转换为 vb.net [英] I need help converting a c# anonymous method to vb.net

查看:13
本文介绍了我需要帮助将 c# 匿名方法转换为 vb.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

provider.OptionsSet += delegate
{
  provider.FinishedLoading();
};

推荐答案

很好的演示了转换器如何严重错误,他们已经有很长时间了.+= 运算符不是 VB.NET 语法,订阅事件需要 AddHandler.Do 来自哪里是任何人的猜测.lambda 不能是函数,除了委托类型返回值的极少数情况.一行三个错误,你没有机会.您需要 VS2010 来编写 Sub lambda.像这样:

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

人 1,机器 0.

这篇关于我需要帮助将 c# 匿名方法转换为 vb.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆