嘿,我有大约 4 个持有各种价值的字典。每个字典对于 4 个字典中的每个字典中的每个项目都具有相同的键。
例子:
dictionary1 (string, string):
key = 523697777, value = "bobs burgers"
key = 89557, value = "Blah blah 1"
key = 598823644, value = "something"
dictionary2 (string, string):
key = 523697777, value = "oats and honey"
key = 89557, value = "juicyfruit"
key = 598823644, value = "sun glasses"
dictionary3 (string, datetime):
key = 523697777, value = 01/05/2013 00:00:00
key = 89557, value = 01/24/2013 00:00:00
key = 598823644, value = 03/12/2013 00:00:00
dictionary4 (string, string):
key = 523697777, value = "Computers"
key = 89557, value = "IM"
key = 598823644, value = "cans"
现在我希望能够循环并从每个字典中获取正确的值,而不必循环遍历每个字典。
目前我正在这样做:
Dim allTogether As New StringBuilder
For Each dict1 In dictionary1
For Each dict2 In dictionary2
If dict1.Key = dict2.Key Then
allTogether.Append(dict1.Value)
allTogether.Append(dict2.Value)
For Each dict2 In dictionary3
If dict2.Key = dict3.Key Then
allTogether.Append(dict3.Value)
For Each dict2 In dictionary3
If dict3.Key = dict4.Key Then
allTogether.Append(dict4.Value)
End If
Next
End If
Next
End If
Next
Next
应该产生:
bobs burgers oats and honey 01/05/2013 00:00:00 Computers
Blah blah 1 juicyfruit 01/24/2013 00:00:00 IM
something sun glasses 03/12/2013 00:00:00 cans
是否可以一键获取数据?