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
- Queue.GetEnumerator Method in C#
- Queue.CopyTo() Method in C#
- Queue.IsSynchronized Property in C#
- Queue.Count Property in C#
- Queue.Dequeue Method in C#
- Queue.Enqueue() Method in C#
- DateTime.DaysInMonth() Method in C#
- DateTime.IsLeapYear() Method in C#
- DateTime.CompareTo() Method in C#
- DateTime.AddTicks() Method in C#
- Queue.ToArray Method in C#
- Queue.Synchronized() Method in C#
- Queue.Peek Method 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.