This works just fine:
protected void txtTest_Load(object sender, EventArgs e)
{
if (sender is TextBox) {...}
}
Is there a way to check if sender is NOT a TextBox, some kind of an equivalent of != for "is"?
Please, don't suggest moving the logic to ELSE{} :)
Two well-known ways of doing it are :
1) Using IS operator:
2) Using AS operator (useful if you also need to work with the textBox instance) :
Try this.
This is one way:
Couldn't you also do the more verbose "old" way, before the
is
keyword:If you use inheritance like:
... Null resistant
or