6
Reply

In which scenario Hashset is used in C# ?

Gnanasekaran P

Gnanasekaran P

9y
4.4k
0
Reply
    To get unique values from a collection holding duplicate values
    HashSet can be used when you dont want set having duplicate values. For example - List dupInts = new List {1,3,4,5,3,3,6}; HashSet noDupInts = new HashSet(dupInts); When this will run - noDupInts will have as {1,3,4,5,6}
    When a collection should have Distinct values then its suggested for Hashset
    HashSet can be used when you dont want set having duplicate values. For example - List dupInts = new List {1,3,4,5,3,3,6}; HashSet noDupInts = new HashSet(dupInts); When this will run - noDupInts will have as {1,3,4,5,6} Hope this helps
    HashSet can be used when you dont want set having duplicate values. For example - List dupInts = new List {1,3,4,5,3,3,6}; HashSet noDupInts = new HashSet(dupInts);When this will run - noDupInts will have as {1,3,4,5,6}Hope this helps
    HashSet Is used when you want to have a collection with unique elements. HashSet stores list of unique elements and won't allow duplicates in it.