The new features in .NET 9 (C# 13)

Tuan DoTuan Do
1 min read

Index Method

foreach ((int index, Product product) in ProductList.Products.Index())
{
    Console.WriteLine($"Index = {index}, Name = {product.Title}");
}

SearchValues (This feature was introduced in .NET 8)

In .NET 8, the SearchValues type is limited to searching by characters. However, in .NET 9, it is possible to search by multiple strings.

ReadOnlySpan<string> searchWords = ["dummy", "text", "and"];
SearchValues<string> searchValues =
    SearchValues.Create(searchWords, StringComparison.OrdinalIgnoreCase);

var searchString =
    """
    Lorem Ipsum is simply dummy text of
    the printing and typesetting industry.
    """;

var index = searchString
    .AsSpan()
    .IndexOfAny(searchValues);
string[] productTitles = ProductList.Products.Select(x => x.Title).ToArray();

SearchValues<string> svProducts = SearchValues.Create(productTitles, StringComparison.OrdinalIgnoreCase);

IEnumerable<Product> found = ProductList.Products
    .Where(x => svProducts.Contains(x.Title));

The downside is you can not use the type Product, only the string.

0
Subscribe to my newsletter

Read articles from Tuan Do directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Tuan Do
Tuan Do

I am a dedicated software engineer with a deep passion for security and a commitment to developing robust and scalable solutions. With over three years of hands-on experience in the .NET ecosystem, I have built, maintained, and optimized various software applications, demonstrating my ability to adapt to diverse project needs. In addition to my expertise in .NET, I have six months of specialized experience working with Spring Boot and ReactJS, further broadening my skill set to include full-stack development and modern web technologies. My professional journey includes deploying small to medium-sized systems to cloud platforms and on-premises environments, where I have ensured reliability, scalability, and efficient resource utilization. This combination of skills and experience reflects my versatility and commitment to staying at the forefront of the ever-evolving tech landscape.