If I am writing code to handle an event from a control on a form as follows:
private void btnButton_Click(object sender, EventArgs e)
{
Button btn = (Button)sender;
btn.Text = "Button pressed"
}
Should I always cast the sender object to its correct type (as I'm doing above), or is it better to explicitly reference the control name, like:
private void btnButton_Click(object sender, EventArgs e)
{
btnButton.Text = "Button pressed"
}
What's the best practice here? I guess I'm probably worrying about this too much though...