Junior
From PDF
Collections
C# Collections
What is a HashSet<T> in C# and when would you use it?
HashSet<T> is a generic collection that stores unique elements with no particular order.
It is optimized for fast lookups, additions, and deletions.
Use case:
When you want to store a collection of unique items without duplicates, such as user IDs,
tags, or keywords.
HashSet<int> uniqueNumbers = new HashSet<int> { 1, 2, 3 };
uniqueNumbers.Add(4);
Share this Q&A
Share preview image: https://www.toolliyo.com/images/toolliyo-logo.png