Home DEVELOPER In .NET 9.0 (17) new: New quantity class readonlyset

In .NET 9.0 (17) new: New quantity class readonlyset

0


.NET 9.0 provides another new volume class: ReadOnlySetAs usual with sets, volumes are in class ReadOnlySet No duplicate is allowed. apart HashSet Developers can do the content ReadOnlySet Do not change




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.

Heise+ Update from April 18, 2025: Read Tips for Easter Weekend

For construction of ReadOnlySet There is a lot as an object with the interface ISet For example, necessary HashSet,

public void ReadOnlySet()
 {
  CUI.Demo();
 
  CUI.H1("HashSet erlaubt Hinzufügen/Löschen");
 
  HashSet set1 = new()
  {
   "www.IT-Visions.de",
   "www.dotnet7.de",
   "www.dotnet8.de",
   "www.dotnet9.de",
   "www.dotnet9.de",
   "www.dotnettraining.de",
  };
 
  var r = set1.Add("www.dotnet9.de");
  Console.WriteLine(r ? "URL neu" : "URL schon vorhanden");
  set1.Remove("www.dotnet7.de");
 
  foreach (var url in set1)
  {
   Console.WriteLine(url);
  }
 
  CUI.H1("ReadOnlySet erlaubt KEINE Duplikate und kein Hinzufügen/Löschen");
  ReadOnlySet set2 = new(set1);
  //set2(0) = "www.dotnet6.de" // nicht erlaubt!
  //set2.Add("www.dotnet9.de"); // nicht erlaubt!
  //set2.Remove("www.dotnet7.de"); // nicht erlaubt!
  foreach (var url in set2) // 4 Elemente, da Duplikate entfernt
  {
   Console.WriteLine(url);
  }
 }



The version of the code reflects the difference between the hashset And readonlyset

(Image: Screenshot (Holgar Shavichenburg))

ReadOnlySet Only .NET fulfills the quantity of reading. Still already ReadOnlyCollection For all quantities IList Proposal, and ReadOnlyDictionary For all quantities with IDictionary, ReadOnlySet The elements are neither allowed to add, change or remove the duplicate.


(RME)

Next American court looks on Google illegal monopoly

NO COMMENTS

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Exit mobile version