UPDATE:
Starting with .Net 4.7.2, HashSet.TryGetValue - docs is available.
HashSet.TryGetValue - SO post
I have a problem with HashSet
because it does not provide any method similar to TryGetValue
known from Dictionary
. And I need such method -- passing element to find in the set, and set returning element from its collection (when found).
Sidenote -- "why do you need element from the set, you already have that element?". No, I don't, equality and identity are two different things.
HashSet
is not sealed but all its fields are private, so deriving from it is pointless. I cannot use Dictionary
instead because I need SetEquals
method. I was thinking about grabbing a source for HashSet
and adding desired method, but the license is not truly open source (I can look, but I cannot distribute/modify). I could use reflection but the arrays in HashSet
are not readonly
meaning I cannot bind to those fields once per instance lifetime.
And I don't want to use full blown library for just single class.
So far I am stuck with LINQ SingleOrDefault
. So the question is how fix this -- have HashSet
with TryGetValue
?