C# HashSet - c# - c# tutorial - c# net
What in C# Hashset ?
- C# HashSet class can be used to store, remove or view elements.
- It does not store duplicate elements.
- It is suggested to use HashSet class if you have to store only unique elements.
- It is found in System.Collections.Generic namespace.
- This is an optimized set collection. It helps eliminates duplicate strings or elements in an array. It is a set that hashes its contents.
Csharp hash function
Syntax:
C# HashSet<T> example
- Let's see an example of generic HashSet<T> class that stores elements using Add() method and iterates elements using for-each loop.
C# examples - Output :
Read Also
dot net developer internship , best sql training institutes in chennai , dot net internshipC# HashSet<T> example 2:
- Let's see another example of generic HashSet<T> class that stores elements using Collection initializer.
C# examples - Output :
Csharp encryption hash function