请问在哪可以找到关于HashTable和Collection的资料啊?
请问在哪可以找到关于HashTable和Collection的资料啊?最好是哪种带例子的!
MSDN讲的还是很清楚的。
顺便写几行:
Dim ht As New Hashtable(10)
ht.Add("tb1", Me.TextBox1) '添加键值
' "tb1"是键,TextBox1是值,字符串"tb1"和TextBox1控件就
'知道了键"tb1"就可以得到对应的值-TextBox1控件
ht.Add("tb2", Me.TextBox2)
ht.Add(3, Me.TextBox3)
ht.Add(Me.TextBox1, Me.Button1)
'键和值可以是任何数据类型,
Dim tb As TextBox
For Each de As DictionaryEntry In ht
'循环hash表包含的每个键值对
MsgBox(de.Key.GetType().Name & ControlChars.CrLf & Convert.ToString(de.Key))
If de.Value.GetType.Name = "TextBox" Then
tb = CType(de.Value, TextBox)
tb.Text = Now.ToString()
End If
Next
'获取hashtable中的值
If ht.Contains("tb1") Then
'hash表中包含"tb1"的键
tb = ht.Item("tb1")
tb.Text = "hello"
Else
'hash表中不包含"tb1"的键
MsgBox("没有键 tb1")
End If
If ht.Contains("tb4") Then
'hash表中包含"tb4"的键
tb = ht.Item("tb4")
tb.Text = "hello"
Else
'hash表中不包含"tb4"的键
MsgBox("没有键 tb4")
End If
CType(ht.Item(TextBox1), Button).ForeColor = Color.Red
'所以很多地方用hashTable很方便