TheDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
is operator evaluates type compatibility and performs pattern matching at runtime. It returns a bool indicating whether the runtime type of an expression is compatible with a specified type or satisfies a specified pattern.
Type Testing
In its most fundamental form, theis operator checks if the runtime type of an expression is compatible with a given type.
true if the following conditions are met:
expressionis notnull.expressioncan be cast toTypevia a reference conversion, a boxing conversion, or an unboxing conversion.
is operator does not consider user-defined conversions or numeric conversions. For example, an int evaluated against a double returns false, even though an implicit numeric conversion exists.
Pattern Matching Syntax
Starting with C# 7.0, theis operator was expanded to support pattern matching, allowing it to evaluate complex conditions, deconstruct types, and extract values simultaneously.
Declaration Pattern
Evaluates type compatibility and, upon a true result, assigns the casted instance to a newly declared local variable.
var pattern always evaluates to true and successfully matches even if the expression evaluates to null.
null, this pattern bypasses any overloaded == or != operators, guaranteeing a safe reference check.
<, >, <=, >=) and combines multiple patterns using logical combinators (and, or, not). The right-hand operand of a relational pattern must be a constant expression; local variables are invalid C# semantics in this context.
Deconstruct method.
..) to match zero or more elements.
Evaluation Rules and Compilation Behavior
- Null Handling: If
expressionevaluates tonull, any type check (expression is Type) strictly returnsfalsebecause there is no allocated instance to possess a type. - Static Typing Warnings: If the compiler determines at compile-time that the
isoperation will always returntrueor always returnfalsebased on the static types of the operands, it generates a compiler warning (CS0183 or CS0184) to indicate redundant code. - Variable Scope: Variables introduced via declaration,
var, positional, or list patterns leak into the enclosing scope. They are definitively assigned only if theisexpression evaluates totrue.
Master C# with Deep Grasping Methodology!Learn More





