rom*_*n m 65 c# asp.net .net-2.0
这很好用:
protected void txtTest_Load(object sender, EventArgs e)
{
if (sender is TextBox) {...}
}
Run Code Online (Sandbox Code Playgroud)
有没有办法检查发件人是不是TextBox,某种等同于!= for"is"?
请不要建议将逻辑移到ELSE {} :)
Jon*_*ury 158
这是一种方式:
if (!(sender is TextBox)) {...}
Run Code Online (Sandbox Code Playgroud)
C# 9 允许使用not运算符。你可以使用
if (sender is not TextBox) {...}
Run Code Online (Sandbox Code Playgroud)
代替
if (!(sender is TextBox)) {...}
Run Code Online (Sandbox Code Playgroud)
你不能在is
关键字之前做更冗长的"旧"方式:
if (sender.GetType() != typeof(TextBox)) { // ... }
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
53981 次 |
最近记录: |