private void buttonCheck(object sender, EventArgs e)
{
Type x = sender.GetType();
var y = Activator.CreateInstance(x); //sends me back to the original problem : sender is an object, not a usable object.
var x = (Button)sender; // == button, but you never know what sender is until it's already in this function... so
dynamic z = sender; //gives you the image of sender i'm looking for, but it's at runtime, so no intellisense/actual compiletime knowledge of what sender is.
}
how do you go about creating a usable instance of sender without prior knowledge of the class sender is actually bringing to this method?
Button button = sender as Button; if (button != null) { //do something with button } else { //do other stuff }
– Miguelif (sender is Button)
– Arakawa(Button)sender
will throwinvalidCastException
, so his option will be to useas
keyword. BTW, I have no idea, what op wants. – Miguelsender
is aListBox
, what do you want to do with thatListBox
then? – Pantin