SortedSet class represents the collection of objects in sorted order. This class comes under the System.Collections.Generic namespace. SortedSet<T>.IntersectWith(IEnumerable<T>) method is used to modify the current SortedSet<T> object so that it contains only elements that are also in a specified collection.
- In C#, SortedSet class can be used to store, remove or view elements.
- It maintains ascending order and does not store duplicate elements.
- It is suggested to use SortedSet class if you have to store unique elements and maintain ascending order.
Here, mySortedSet1 and mySortedSet2 are two SortedSet’s object.
Exception: This method will give ArgumentNullException if the SortedSet is null.
Below given are some examples to understand the implementation in a better way:
The intersection of mySortedSet1 and mySortedSet2: 4 8
The Intersection of mySortedSet1 and mySortedSet2 is: Geeks Noida
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.