![]() |
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 remove the specified element from a HashSet<T> object. Syntax: public bool Remove (T item); Here, item is the element which is to be removed. 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.Remove(T) Method: Example 1: CSHARP
Output:
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 Example 2: CSHARP
Output:
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 Reference: |
Reffered: https://www.geeksforgeeks.org
C# |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 9 |