Migrating 'Handles' from VB.NET to C#

Deadly 提交于 2019-11-28 01:01:37

I recommend using the Telerik Code Converter as a start.

C# does not have that easy automatic attaching of event handlers by means of the "Handles" keyword like VB.NET does.

//EventHandler declaration
public event EventHandler  DataLoaded;
protected void Mag_Button_Load_Click(object sender, EventArgs e)
{

    //Raise Event
    if (DataLoaded != null) {
        DataLoaded(this, EventArgs.Empty);
    }
}

Also, You need to assign your event handlers to the objects like this:

Button1.Click += Button1_Click;

protected void Button1_Click(object sender, EventArgs e)
{
  //do something.
}

However C# does have the succinct ability of doing this as well:

Button1.Click += (sender, e)=>
{
    //do something
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!