A HashSet is an unordered collection of the unique elements. It comes under 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<T>.Remove(T) method is used to removes the specified element from a HashSet<T> object.
public bool Remove (T item);
Here, item is the element which is to be remove.
Return Value: The method returns True if the element is successfully found and removed and returns False if item is not found in the HashSet<T> object.
Below examples illustrate the use of HashSet
The elements in HashSet are : 0 2 4 6 8 10 12 14 16 18 Number of elements are : 10 The elements in HashSet are : 0 2 4 6 8 12 14 16 18 Number of elements are : 9
The elements in HashSet are : Data Structures Algorithms Java Puzzles Coding Number of elements are : 5 The elements in HashSet are : Data Structures Algorithms Java Puzzles Coding Number of elements are : 5
- C# | Remove all elements from a HashSet
- C# | Remove all elements in a collection from a HashSet
- C# | Remove elements from a HashSet with conditions defined by the predicate
- C# | Add element to HashSet
- C# | Check if a HashSet contains the specified element
- C# | Remove the element with the specified key from the Hashtable
- C# | Remove the element with the specified key from a SortedList
- C# | Remove element at specified index of Collection<T>
- C# | Remove the element at the specified index of the ArrayList
- C# | How to remove the element from the specified index of the List
- C# | Union of two HashSet
- C# | HashSet Class
- HashSet in C# with Examples
- C# | Getting an enumerator that iterates through HashSet<T>
- C# | Create HashSet from another collection
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.