ShareThis

Monday, June 18, 2012

C# - Iterate over a HashSet

You can use a HashSet<T>.Enumerator, but that is unnecessary. The same can be accomplished using a foreach loop as it hides the complexity of the enumerator.

Example:


HashSet<int> valueSet = new HashSet<int>();
foreach (int value in valueSet)
{
 // use your hash set values here!   
}

Related StackOverflow Questions: 

What is the fastest/safest method to iterate over a HashSet?

0 comments:

Post a Comment