Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieve an object from hashset in C# [duplicate]

Tags:

c#

hash

Possible Duplicate:
Why can't I retrieve an item from a HashSet without enumeration?

I need to add a lot of objects to a Set.and I should retrieve them very fast. The only way that I know is using hash. But the HashSet class in C# doesn't contain any 'Get' method. The dictionary class isn't useful because Finding an object is very time-consuming in a dictionary.

like image 564
Masoud Avatar asked Jan 06 '11 10:01

Masoud


People also ask

Is there a GET method in HashSet?

HashSet does not have a get method to retrieve elements. HashSet implements the Set interface. The Set is a collection with no duplicates.

What is a HashSet in C?

A HashSet is an optimized collection of unordered, unique elements that provides fast lookups and high-performance set operations. The HashSet class was first introduced in . NET 3.5 and is part of the System. Collection.


1 Answers

HashSets are basically used to test if an object is included in the collection. It is un-orderd and un-sorted, doesnt have an index that could be used to retrive an object.

If you need to store and retrieve objects, use other collection types like List, HashTable etc.

like image 83
Danish Khan Avatar answered Oct 13 '22 02:10

Danish Khan