A HashSet is an unordered collection of the unique elements. It is found in System.Collections.Generic namespace. It is used in a situation where we want to prevent duplicates from being inserted in the collection. As far as performance is concerned, it is better in comparison to the list. HashSet
Here mySet1 and mySet2 are the two HashSets.
Exception: This method will give ArgumentNullException if the HashSet is null.
Below given are some examples to understand the implementation in a better way:
Elements in Set 1 : 0 2 4 6 8 Elements in Set 2 : 1 3 5 7 9
- C# | Intersection of SortedSet with a collection
- C# | Int16.ToString Method | Set - 1
- C# | Int16.ToString Method | Set - 2
- Int16.GetHashCode Method in C# with Examples
- Int16.Equals Method in C# with Examples
- Int16.GetTypeCode Method in C# with Examples
- Difference between Method Overriding and Method Hiding in C#
- Decimal.FromOACurrency() Method in C#
- Graphics.DrawArc() Method in C# with Examples
- Decimal.Round() Method in C# | Set - 1
- Decimal.GetHashCode Method in C# with Examples
- Decimal.GetTypeCode Method in C# with Examples
- Decimal.CompareTo() Method in C#
- Method Hiding in C#
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.