---
title: "SearchValues object become better with .NET 9"
description: "`SearchValues,` which were introduced with .NET 8 will become an upgrade and becomes more usable! Let's see how."
updated: 2024-02-02
tags: ["C#", ".NET", ".NET 9"]
canonical: "https://steven-giesel.com/blogPost/080c8f82-f376-489f-a304-72d419978294/searchvalues-object-become-better-with-net-9"
---

# SearchValues object become better with .NET 9

`SearchValues,` which were introduced with .NET 8 will become an upgrade and becomes more usable! Let's see how.

## What is `SearchValues`?

[`SearchValues`](https://learn.microsoft.com/en-us/dotnet/api/system.buffers.searchvalues-1?view=net-8.0) is a new type that was introduced with .NET 8. It is a type that is used to represent the values that are used in a search. Here a basic example:

```csharp
SearchValues<char> searchValues = SearchValues.Create(new[] { 'a', 'e', 'i', 'o', 'u' });

Console.WriteLine(ContainsVowel("Hello, World!")); // Returns true

bool ContainsVowel(ReadOnlySpan<char> text) => text.ContainsAny(searchValues);
```

Until now we are limited. We can only search for `char` values. But what if we want to search for `string` values aka text inside other text? Well, we can't. But with .NET 9 we can! There are new overloads and basically `SearchValues` is applicable to text as well:

```csharp
SearchValues<string> Names = SearchValues.Create(
        ["Steven", "Sherlock", "Holmes", "Michael", "Scott"],
        StringComparison.OrdinalIgnoreCase);

const string TextWithNames = "This is Steven and Michael. You know Michael Scott from the office. ";

var index = MemoryExtensions.ContainsAny(TextWithNames, Names);
Console.WriteLine(index); // Returns true
```