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{} :)
To determine whether an object is a specific type, you can use your language's type comparison keyword or construct. For example, you can use the TypeOf… Is construct in Visual Basic or the is keyword in C#. The GetType method is inherited by all types that derive from Object.
You can check object type in Java by using the instanceof keyword. Determining object type is important if you're processing a collection such as an array that contains more than one type of object. For example, you might have an array with string and integer representations of numbers.
A string is an object of type String whose value is text. Internally, the text is stored as a sequential read-only collection of Char objects. There's no null-terminating character at the end of a C# string; therefore a C# string can contain any number of embedded null characters ('\0').
NULL checks in C# v.We also use NULL propagation method for NULL check. The question mark symbol which used in if condition, which means that it'll check whether value is NULL, if not then it'll check whether Name is null. It'll check if the value is Null, if Null it'll return “value is null” string.
This is one way:
if (!(sender is TextBox)) {...}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With