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)
{
}
}
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.
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.
The not-equal-to operator ( != ) returns true if the operands don't have the same value; otherwise, it returns false .
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.
In this case, wrap and check the boolean opposite:
if (!(err is ThreadAbortException))
Just change the catch block to:
catch(ThreadAbortException ex)
{
}
catch(Exception ex)
{
}
so you can handle ThreadAbortExceptions and all others separately.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With