# Pattern Matching

Testing a value's type, shape, or contents while optionally extracting parts of it.

## What is **Pattern Matching** in C#?

**Pattern Matching** — Testing a value's type, shape, or contents while optionally extracting parts of it.

```csharp
class LabelReader
{
    int LengthOf(object value)
    {
        if (value is string text)
        {
            return text.Length;
        }

        return 0;
    }
}
```

Level: Journeyman · [More C# terms at this level](https://www.ask-codey.com/glossary/subjects/c-sharp/journeyman)

Updated: September 27, 2026

Source: https://www.ask-codey.com/glossary/pattern-matching
