Check if object is NOT of type (!= equivalent for “IS”) - C#

后端 未结 6 1477
遥遥无期
遥遥无期 2020-12-29 19:16

This works just fine:

    protected void txtTest_Load(object sender, EventArgs e)
    {
        if (sender is TextBox) {...}

    }

Is ther

6条回答
  •  时光说笑
    2020-12-29 19:47

    Try this.

    var cont= textboxobject as Control;
    if(cont.GetType().Name=="TextBox")
    {
       MessageBox.show("textboxobject is a textbox");
    } 
    

提交回复
热议问题