> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# C# Is

The `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, the `is` operator checks if the runtime type of an expression is compatible with a given type.

```csharp theme={"dark"}
expression is Type
```

The operation evaluates to `true` if the following conditions are met:

* `expression` is not `null`.
* `expression` can be cast to `Type` via a reference conversion, a boxing conversion, or an unboxing conversion.

The `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, the `is` 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.

```csharp theme={"dark"}
expression is Type variableName
```

**var Pattern**
Matches any expression and assigns it to a newly declared local variable. Unlike type declaration patterns, the `var` pattern always evaluates to `true` and successfully matches even if the expression evaluates to `null`.

```csharp theme={"dark"}
expression is var variableName
```

**Constant Pattern**
Evaluates whether the expression equals a specified constant value. When evaluating `null`, this pattern bypasses any overloaded `==` or `!=` operators, guaranteeing a safe reference check.

```csharp theme={"dark"}
expression is null
expression is 42
```

**Relational and Logical Patterns**
Evaluates the expression against relational operators (`<`, `>`, `<=`, `>=`) 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.

```csharp theme={"dark"}
expression is >= 0 and <= 100
expression is not Type
```

**Property Pattern**
Evaluates whether the expression matches a specific type and recursively applies patterns to the properties or fields of that instance.

```csharp theme={"dark"}
expression is Type { PropertyName: nestedPattern }
```

**Positional (Deconstruction) Pattern**
Deconstructs an expression into its component parts and applies nested patterns to those parts. This requires the expression type to be a tuple or to possess a compatible `Deconstruct` method.

```csharp theme={"dark"}
expression is (int x, int y)
expression is Type (nestedPattern1, nestedPattern2)
```

**List Pattern**
Evaluates sequences (such as arrays, lists, or spans) to match elements against nested patterns. It supports the slice pattern (`..`) to match zero or more elements.

```csharp theme={"dark"}
expression is [1, 2, ..]
expression is [var first, .., var last]
```

## Evaluation Rules and Compilation Behavior

* **Null Handling:** If `expression` evaluates to `null`, any type check (`expression is Type`) strictly returns `false` because there is no allocated instance to possess a type.
* **Static Typing Warnings:** If the compiler determines at compile-time that the `is` operation will always return `true` or always return `false` based 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 the `is` expression evaluates to `true`.

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor C# Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
