简体   繁体   English

VB.NET中的C#event + = delegate {}等效

[英]C# event += delegate {} equivalent in VB.NET

Well, I was translating a C# into VB.NET using developer fusion , and the API didn't translated me that part... 好吧,我正在使用开发人员融合C# into VB.NET翻译C# into VB.NET ,并且API没有将我翻译成那部分......

owner.IsVisibleChanged += delegate
            {
                if (owner.IsVisible)
                {
                    Owner = owner;
                    Show();
                }
            };

I know that += is for AddHandler owner.IsVisibleChanged, AdressOf (delegate??) , so, which is the equivalent for that part? 我知道+= is for AddHandler owner.IsVisibleChanged, AdressOf (delegate??) ,那么,哪个是该部分的等价物?

Thanks in advance. 提前致谢。

PD: I don't enough money for buy .NET Reflector :( And I wasted the trial. PD:我没有足够的钱购买 .NET Reflector :(而且我浪费了试验。

There are two parts here. 这里有两个部分。

  1. Anonymous methods. 匿名方法。 delegate in C# roughly corresponds to an anonymous Sub in VB here. C#中的delegate大致对应于VB中的匿名Sub

  2. Adding event handlers. 添加事件处理程序。 += in C#, AddHandler in VB. +=在C#中, AddHandler在VB中。

Putting it together: 把它放在一起:

AddHandler owner.IsVisibleChanged, _
    Sub()
        …
    End Sub

Incidentally, the AddressOf operator you've mentioned is used in VB to refer to a (non-anonymous) method without calling it. 顺便提一下,您提到的AddressOf运算符在VB中用于引用(非匿名)方法而不调用它。 So you would use it here if you would refer to an existing, named method rather than an anonymous method. 因此,如果您要引用现有的命名方法而不是匿名方法,那么您将在此处使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM