我需要将C#匿名方法转换为vb.net的帮助 [英] I need help converting a c# anonymous method to vb.net
问题描述
provider.OptionsSet += delegate
{
provider.FinishedLoading();
};
推荐答案
很好的演示了转换器如何将这种错误弄错了,这已经有很长时间了.+ =运算符不是VB.NET语法,需要AddHandler来订阅事件.有人猜测 Do 的来源.Lambda不能是Function,除非在极少数情况下委托类型返回值.一行中有三个bug,您没有机会.您需要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屋!