views:

47

answers:

1

Would the following:

Dim stringlist As List(Of String)
Dim stringlisthas = stringlist.Contains("thing1")

be any slower than

Dim stringlist As List(Of String)
Dim stringlisthash As New HashSet(Of String)(stringlist)
Dim stringlisthas = stringlisthash.Contains("thing1")

Is a hashset needed for contains?

+1  A: 

Is a hashset needed for contains?

Needed? No.

Would [List<T>.Contains] be any slower than [HashSet<T>.Contains]?

Probably. It depends on how List<T>.Contains is implemented (its probably a linear search).

I'll answer a question you didn't ask.

Does it matter?

It depends. You have to code up both, profile it, and see if it's a bottleneck in your application. If it's not, just stick with List<T>.Contains.

Jason