The new features in .NET 9 (C# 13)
Tuan Do Quoc
1 min read
Table of contents
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 Quoc directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Tuan Do Quoc
Tuan Do Quoc
I'm a software engineer with a strong enthusiasm for security. I possess more than 2 years of hands-on experience with the .NET ecosystem, complemented by an additional 6 months specializing in Spring Boot and ReactJS. Experienced in deploying small and medium-sized systems to the cloud as well as on-premises.