C#到VB:Class.Event + =(发件人,参数)=>使用functionName(PARAMS) [英] C# to VB: Class.Event += (sender, args) => FunctionName(params)

查看:374
本文介绍了C#到VB:Class.Event + =(发件人,参数)=>使用functionName(PARAMS)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想转换此网页以VB,C#代码。



一切似乎都转换使用在线转换工具,非常精美,但后来我到了下面一行:

  fadeOutAnimation.Completed + =(发件人,参数)=> OnFadeOutAnimationCompleted(D,hostGrid,网格); 



的fadeOutAnimation.Completed事件产生的事件与签名(发件人,参数),以及d,hostGrid和网格是局部变量包含这个神秘的事件处理程序分配的功能。



我想我可以看到,在这个C#线的指示告诉代码执行OnFadeOutAnimationCompleted功能,采用D,hostgrid和电网作为参数,当发生fadeoutAnimation.Completed,但我不知道,甚至为了复制在VB.net这种行为寻找。



可有人为我提供一些术语,所以我可以更好地教育自己的一切这就是所谓的?


解决方案

 的AddHandler fadeOutAnimation.Completed,子()
OnFadeOutAnimationCompleted(D,hostGrid,网格)
端子

这已经有一段时间,但因为你不是在事件处理程序使用的参数,我不认为你需要将它们包括(因为宽松委托转换的)。如果是这样,它会看起来更像是:



 的AddHandler fadeOutAnimation.Completed,子(发件人为对象,以ARGS EventArgs的)
OnFadeOutAnimationCompleted(D,hostGrid,网格)
端子


I'm trying to convert the C# code from this webpage to VB.

Everything seems to have converted pretty much fine using an online converter tool, but then I reach the following line:

fadeOutAnimation.Completed += (sender, args) => OnFadeOutAnimationCompleted(d, hostGrid, grid);

The fadeOutAnimation.Completed event produces an event with the signature (sender, args), and d, hostGrid and grid are variables local to the function containing this mysterious event handler assignment.

I think I can see that the instruction on this C# line is telling the code to execute the OnFadeOutAnimationCompleted function, using d, hostgrid and grid as parameters, when fadeoutAnimation.Completed occurs, but I have no idea what to even search for in order to replicate this behaviour in VB.net.

Can someone provide me with some terminology so I can better educate myself on whatever this is called?

解决方案

AddHandler fadeOutAnimation.Completed, Sub() 
    OnFadeOutAnimationCompleted(d, hostGrid, grid)
End Sub

It's been a while, but since you're not using the parameters in the Event Handler I don't think you need to include them (because of Relaxed Delegate Conversion). If so, it'll look more like:

AddHandler fadeOutAnimation.Completed, Sub(sender as object, args as EventArgs) 
    OnFadeOutAnimationCompleted(d, hostGrid, grid)
End Sub

这篇关于C#到VB:Class.Event + =(发件人,参数)=>使用functionName(PARAMS)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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