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# Program to Convert a Binary String to an Integer
- Basics of FileStream in C#
- C# Program for Nested Conditional Operator
- C# Program for Converting Hexadecimal String to Integer
- Program to Input Weekday Number and Print the Weekday in C#
- What is NuGet?
- Top 10 Programming Languages for Blockchain Development
- C# Program to Convert the Octal String to an Integer Number
- int Keyword in C#
- ulong keyword in C#
- long keyword in C#
- ushort keyword in C#
- short keyword 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.