Well, let's say that there is a class:
Person, which contains the ID and FIO.
There, the Equals method and GetHashCode method are redefined so that it compares the ID to determine uniqueness.
Let's say I will store all this in a HashSet . However, how can I quickly get the actual item from my collection if necessary?
The TryGetValue method has been added to the latest version of the Framework. It turns out that I can only get through the search?
The dictionary seems to me that using it is unnecessarily a Dictionary<Person,Person> ...
UPD
My motivation is that why should I use a Dictionary if the element itself can be a key => when creating a HashSet I can pass a custom comparator, which for example will support uniqueness by ID, and then I would like to get the current value from the hash through Hash.TryGetValue(new Person(){ID=100500})
Dictionary<IdType, Person>used for a similar purpose. So what to do? - Alexander Petrov