New in .NET 9.0 (18): Searchwalues ​​and Priority Queue Embarrassment

0
5
New in .NET 9.0 (18): Searchwalues ​​and Priority Queue Embarrassment


Class is already introduced in .NET 8.0 System.Buffers.SearchValues Now the method is Create() Not only to search for individual characters, but also another surcharge for the whole wire in a separate string:




Dr. Holgar Schwichtenberg is the technical manager of experts to www.it-vistions.de, which supports many medium sizes and large companies through advice and training with 53 famous experts as well as software development. Through his appearance in many national and international expert conferences as well as his appearance in more than 90 expert books and more than 1,500 expert articles, Holgar Schwichtanberg is one of the most famous experts for .NET and web techniques in Germany.

// In .NET 8.0 möglich
SearchValues digits = SearchValues.Create("0123456789");
string text1 = "Hinweis: Der Buchstabe A hat in der ASCII-Tabelle den Wert 97.";
var positionDerErstenZiffer = text1.AsSpan().IndexOfAny(digits);
Console.WriteLine(positionDerErstenZiffer); // 59
 
// Ab .NET 9.0 möglich
SearchValues artikel =
SearchValues.Create(("der", "die", "das"), StringComparison.OrdinalIgnoreCase);
string text2 = "Hinweis: Der Buchstabe A hat in der ASCII-Tabelle den Wert 97.";
var positionDesErstenArtikels = text2.AsSpan().IndexOfAny(artikel);
Console.WriteLine(positionDesErstenArtikels); // 9

PriorityQueue-Class, already introduced in .NET 6.0, is now one Remove()-Methode can be used to remove elements, even if they are not bend. Remove() As a parameter, the removed element expanded.

Remove() Distribute three values: As an withdrawal value, a booler value that shows that the element was present and it could be removed. The second and third method comes through in parameters out Removed elements and its priority.

Shows the use of the following code method Remove In class PriorityQueue,

Ki-Update Deep-Dive: How AI Grid AI designs the future of researchKi-Update Deep-Dive: How AI Grid AI designs the future of research

public void PriorityQueueRemove()
{
 CUI.Demo();
 
 CUI.H2("PriorityQueue erstellen");
 var q = new PriorityQueue();
 q.Enqueue("www.dotnet-doktor.de", 20);
 q.Enqueue("www.dotnet7.de", 2);
 q.Enqueue("www.IT-Visions.de", 10);
 q.Enqueue("www.dotnet-lexikon.de", 30);
 q.Enqueue("www.dotnet8.de", 3);
 q.Enqueue("www.dotnet9.de", 1);
 
 Console.WriteLine($"Elemente in der PriorityQueue: {q.Count}"); // 0
 
 CUI.H2("Entferne vorhandenes Element aus der PriorityQueue mit Remove()");
 bool b1 = q.Remove("www.dotnet7.de", out string e1, out int priority1); // .NET 7.0 raus, da Out of Support!!! 
 if (b1) Console.WriteLine($"Element {e1} mit Priorität {priority1} wurde entfernt!");
 else Console.WriteLine("Element nicht gefunden");
 Console.WriteLine($"Elemente in der PriorityQueue: {q.Count}"); // 0
 
 CUI.H2("Versuch, nicht vorhandenes Element aus der PriorityQueue zu entfernen mit Remove()");
 bool b2 = q.Remove("www.dotnet7.de", out string e2, out int priority2);
 if (b2) Console.WriteLine($"Element {e2} mit Priorität {priority2} wurde entfernt!");
 else Console.WriteLine("Element nicht gefunden");
 
 CUI.H2($"Alle Elemente {q.Count} aus der Warteschlange holen mit Dequeue()"); // 5
 var count = q.Count;
 for (int i = 0; i < count; i++)
 {
  var current = q.Dequeue();
  Console.WriteLine(i + ": " + current);
 }
 
 Console.WriteLine($"Verbliebene Elemente in der PriorityQueue: {q.Count}"); // 0
}



The screenshot code shows the version of the example.

(Image: Screenshot (Holgar Shavichenburg))


Online Conference Bettercode () 10.0 on 18 November, 2025

Online Conference Bettercode () 10.0 on 18 November, 2025

(Image: coffeemill/123rf.com)

Next LTS releases are coming: Online Conference Bettercode () .NET 10.0 In collaboration with the most important innovations with IT-VINTS.DE-PRESENTs organized by IX and dpunkt.verlag on 18 November 2025. These include .NET 10.0 SDK and C# 14.0, ASP.NET Core 10.0, Blazor 10.0, Windows Forms 10.0, WPF 10.0, Winui 3, .NET Maui 10.0 and .NET applications include integration of artificial intelligence.

The program has not been published yet-till then again there are already blind bird tickets. In online shop Available. Last year program Can be seen in collection,


(RME)

LEAVE A REPLY

Please enter your comment!
Please enter your name here