I am developing a WinForms application using the MVP pattern. I would like to pass the button clicked tag value to the presenter. Because I want to get the button.Tag property I need the sender argument to be of type Button. How can I do this with out doing this:
private void button0_Click(object sender, EventArgs e) { if (sender is Button) { presenter.CheckLeadingZero(sender as Button); } }
I am having to downcast the object to a button in the method parameter.
There is no point in checking the type using the
iskeyword if you’re just going to use theaskeyword, becauseasdoes anischeck followed by an explicit cast anyway. Instead, you should do something like this: