Dim colnames As New Dictionary(Of String, String)
'Dim prng As New Random
'Const alphas As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Private Function RndColName() As String
Dim sb As Guid
Dim s As String
'Dim ct As Integer = 0
sb = Guid.NewGuid
s = sb.ToString.Replace("-", "")
's = alphas(prng.Next(alphas.Length)) & s & alphas(prng.Next(alphas.Length))
'ct += 1
'If ct > 3 Then
Loop While colnames.ContainsKey(s)
Yes, something like that. HashSet would be marginally better than the Dictionary or HashTable classes so you don't need values, just keys.
So hashtables have better performance than a List(Of T) - would not have thought that.
Yes, hashtables are designed for fast lookup. In short, the hashtable performs some calculation (the hash function) on the object to be stored. This calculation comes up with an integer that determines what array index the object gets stored at. To see if an object is in the hashtable, perform the same calculation and see if the object is in that array index. No matter how big the hashtable, if the table and hash function are designed well, the lookup will take a constant amount of time.
Using a list, the item you are looking for could be anywhere so you have to scan the items one by one. In this case especially, you are hoping that the item won't be there so most of the time you will scan the entire list. If the list grows large, you might notice the time it takes to scan.
For small sets of data the list likely performs better.
Depends on the implementations, of course - again, I'm not a VB guy, so I'd have to check the details - but typically, no. A hash is basically a fast artithmetic process: it takes a large number and returns a number in a smaller space. This value is then used to index into a table. Hash tables can get slow, but usually that'll be because you're trying to hash into too small a space and you're getting collisions. Performance of a list depends on the implementation. An array-backed list can do fast lookup, a linked list can't. Don't know what VB uses, but the upshot is, your list probably doesn't perform much better than the hash table, if at all, and it might be significantly worse.