Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IS NOT operator in C#

Tags:

operators

c#

I can't find the "is not" operator in C#. For example I have the code below which does not work. I need to check that err is not of type class ThreadAbortException.

    catch (Exception err)
    {
        if (err is not ThreadAbortException)
        {
        }
    }
like image 319
Tomas Avatar asked Mar 04 '10 15:03

Tomas


People also ask

Does C have a not operator?

C NOT Logical Operator is used to inverse the result of a boolean value or an expression. ! is the symbol used for NOT Logical Operator in C programming. C NOT Operator takes only one boolean value as operand and returns the result of NOT operation.

Which operator is not?

In Boolean algebra, the NOT operator is a Boolean operator that returns TRUE or 1 when the operand is FALSE or 0, and returns FALSE or 0 when the operand is TRUE or 1. Essentially, the operator reverses the logical value associated with the expression on which it operates.

What does != In C mean?

The not-equal-to operator ( != ) returns true if the operands don't have the same value; otherwise, it returns false .

What type of operator is and or and NOT?

Logical Operators are used to perform logical operations and include AND, OR, or NOT. Boolean Operators include AND, OR, XOR, or NOT and can have one of two values, true or false.


2 Answers

In this case, wrap and check the boolean opposite:

if (!(err is ThreadAbortException))
like image 114
Nick Craver Avatar answered Nov 11 '22 15:11

Nick Craver


Just change the catch block to:

catch(ThreadAbortException ex)
{
}
catch(Exception ex)
{
}

so you can handle ThreadAbortExceptions and all others separately.

like image 27
Lee Avatar answered Nov 11 '22 16:11

Lee