# C# Tip : List Patterns

**List patterns** in C# (12 or above) allow you to match elements within a collection using pattern matching syntax. They help you check if a list has certain elements, a specific structure, or a particular number of items—making your code more readable and expressive when working with arrays or lists.

### Example

Here's a simple example of **list patterns** in C#:

```csharp
int[] numbers = { 1, 2, 3 };

if (numbers is [1, 2, 3])
{
    Console.WriteLine("Exact match: [1, 2, 3]");
}
```

### Explanation:

* The condition ***numbers is \[1, 2, 3\]*** checks if the array **exactly matches** the pattern: it has three elements, in the same order, with those exact values.
    
* If it matches, the code inside the ***if*** block runs.
    

### Partial match

You can also do **partial matches**:

```csharp
if (numbers is [1, ..])
{
    Console.WriteLine("Starts with 1");
}
```

* **<mark>..</mark>** means "any number of elements after" — this checks if the array **starts with 1**, regardless of how many elements come after it.
    
* For more information about List Patterns, refer [https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/patterns#list-patterns](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/patterns#list-patterns)
