SearchValues object become better with .NET 9

2/2/2024

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

What is SearchValues?

SearchValues 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:

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:

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

Three new LINQ methods in .NET 9

Even though we are in the alpha of .NET 9 and .NET 8 was released not more than two months ago, the dotnet team does not sleep and pushes new changes! In this blog post, we are checking what new methods were added to everyones favorite: LINQ.

Swagger Replacement in ASP.NET 9

You might have heard that Swagger is removed in the templates of ASP.NET 9. So this blog post will show you alternatives.

A new lock type in .NET 9

There is a new sheriff in town when it comes to the lock keyword, And that is the new System.Threading.Lock type that is introduced in .NET 9. And yes, I know - we still need time to digest the big .NET 8 release.

An error has occurred. This application may no longer respond until reloaded. Reload x