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

roman m picture roman m · Feb 9, 2009 · Viewed 59.9k times · Source

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{} :)

Answer

Jon Tackabury picture Jon Tackabury · Feb 9, 2009

This is one way:

if (!(sender is TextBox)) {...}