The requested page is not available for the requested platform. You are viewing the content for Default platform.

Empty event handler

CodeRush Classic shows the Empty event handler code issue if an event handler is empty.

Fix

Remove the empty event handler.

Purpose

Empty event handler directs your attention to empty event handlers, which can be removed to improve your code readability.

Example

public Button CreateButton()
{
    Button myButton = new Button();
    myButton.Text = "Click me";
    myButton.Click += myButton_Click;
    myButton.Enter += myButton_Enter;
    return myButton;
}
void myButton_Click(object sender, EventArgs e)
{
    Console.WriteLine("Button clicked");
}
void myButton_Enter(object sender, EventArgs e)
{

}

Fix:

public Button CreateButton()
{
    Button myButton = new Button();
    myButton.Text = "Click me";
    myButton.Click += myButton_Click;
    return myButton;
}
void myButton_Click(object sender, EventArgs e)
{
    Console.WriteLine("Button clicked");
}