Dim uniqueList As New HashSet(Of Int32)
uniqueList.Add(intNumber)
For Each intNumber In uniqueList
'do something with the variable
Next
I have a process that loops through orders, sends email, and sets a status (that the email has been sent). But, there are several emails per order. When I sent the first email and set the status, the second and third email didn't send because the 'sent' status had been sent.
The solution was to move the setting of the status out of the loop, and add the order number to a list, and then set the status in a loop after the first. But I didn't want to set the status more than once, and then would have happened if I had used an array or the more modern Generic List (Of t).
But... HashSets have a unique key, and won't add a non-unique item. If you were to repeat the second line in the code above... you'd only have one item in the list.
So... I learned something today, thought I'd share it with you.