检查对象的类型是不是 - C#(=相当于" IS&QUOT!)
问题描述:
这只是正常工作:
protected void txtTest_Load(object sender, EventArgs e)
{
if (sender is TextBox) {...}
}
有没有一种方法来检查,如果发件人不是一个TextBox,某种!等效的=为是?
Is there a way to check if sender is NOT a TextBox, some kind of an equivalent of != for "is"?
请,不建议移动逻辑ELSE {}:)
Please, don't suggest moving the logic to ELSE{} :)
答
这是一个方法:
if (!(sender is TextBox)) {...}