HashSet(T).Clear Method removes all elements from a HashSet(Of T) object.
Imports System
Imports System.Collections.Generic
Class Program
Shared Sub Main()
Dim Numbers As HashSet(Of Integer) = New HashSet(Of Integer)()
For i As Integer = 0 To 9
Numbers.Add(i)
Next i
Console.Write("Numbers contains {0} elements: ", Numbers.Count)
Numbers.Clear()
Numbers.TrimExcess()
Console.Write("Numbers contains {0} elements: ", Numbers.Count)
End Sub
End Class
Related examples in the same category