Tech Featured
  • Home
  • Apple
  • Apps
  • Automobiles
  • Gadgets
  • Gaming
  • Reviews
  • Tech Tips
No Result
View All Result
  • Home
  • Apple
  • Apps
  • Automobiles
  • Gadgets
  • Gaming
  • Reviews
  • Tech Tips
No Result
View All Result
Tech Featured
No Result
View All Result
Home News

C# HashSet Advantages

Mar 21, 2017
in News
Reading Time: 1 min read
0

A Set data structure was finally added to C# in the .NET Framework 3.5. It is a powerful data structure that makes life a little easier for programmers…

The C# Set is called a HashSet. It is modeled after a math set, meaning that elements must be unique. In other words a Set guarantees that there are no duplicate elements.

Now why create a Set data structure in C# when one could simply check a list before adding an element to see if it already exists? The answer: it is because searching a run-of-the-mill list is slow. A HashSet is fundamentally designed to allow fast searches, making inserts faster.

There are different implementations of Sets. Some make insertion and lookup operations super fast by hashing elements. However that means that the order in which the elements were added is lost. Other implementations preserve the added order at the cost of slower running times.

The HashSet class in C# goes for the second approach, thus preserving the order of elements. It is still much faster than a regular List. Some basic benchmarks showed that HashSet is decently faster when dealing with primary types (int, double, bool, etc.). It is a lot faster when working class objects. So that point is that HashSet is fast.

The only catch of HashSet is that there is no access by indices. To access elements you can either use an enumerator or use the built-in function to convert the HashSet into a List and iterate through that.

Previous Post

Google Is Under Pressure Because Brands Are Pulling Adverts Over Hate Speech Fears

Next Post

Apple's New App Makes Video Editing Stupid Easy

techfeatured

techfeatured

Next Post

Apple's New App Makes Video Editing Stupid Easy

For any queries, you can reach us at [email protected]

Latest Posts

  • GTA 6 Pre-Load Starts November 10 and Needs Up to 212GB: How to Get Ready
  • Siri AI Is Now Open to Every App, and the Fine Print Says Extra Access Will Cost Money
  • The Average New Phone Now Costs $442, a Record, and Budget Buyers Take the Hardest Hit
  • Anthropic’s FlashProve Gives AI Answers a Receipt, and It Costs 70 Times the Compute to Print One
  • iOS 27.3 Beta 1 Is Live: the Health App Returns, StandBy Reaches Older iPhones, and the Duo Gets One-Handed Mode
  • Guest Posts
  • Advertise
  • Contact Us
  • Privacy Policy

© 2026 JNews - Premium WordPress news & magazine theme by Jegtheme.

No Result
View All Result
  • Home
  • Apple
  • Apps
  • Automobiles
  • Gadgets
  • Gaming
  • Reviews
  • Tech Tips

© 2026 JNews - Premium WordPress news & magazine theme by Jegtheme.