How to get the element from hashset that is known to contain exactly 1 element? (without iterating it)
How to get the element from hashset that is known to contain exactly 1 element? (without iterating it)
I had a HashSet<object> that for some reason couldn't be accessed with [0] or .First().
Though technically iterating, I'm leaving this here just in case someone else with my issue runs into this post.
foreach (var i in myHash){
object o = i;
break;
}
Simply start to iterate, then immediately break the iteration.