0

我在 VB.NET windows 应用程序中使用数据字典。

我正在尝试使用 for 循环从字典中获取数据。

前任。我有下面的字典表,我想使用 for 循环获取值。

AAA - "0"   
BBB - "0" 
CCC - "0' 
DDD - "0"
 For i As Integer = 0 To CatDictionaryNEW1.Count
' for each i I want to fetch the values using index of data dictionary
' when i = 0 then AAA should return
' when i =1 then BBB should return 
' and so on....
 next 

这个怎么做 ?

4

1 回答 1

0

you do not need to iterate the entire dictionary to test AAA or BBB (they are not Lists or Arrays):

 If CatDictionaryNEW1("AAA") = 0 Then
      do whatever
 End If

 If CatDictionaryNEW1("BBB") = 1 Then
      do whatever
 End If

You would need to walk thru the entire dictionary if you needed to find WHICH item or element contained a certain value:

  For each kvp as KeyValuePair in myDict
       if kvp.Value = MagicValue then
           Return kvp.Key
       End if
  Next
于 2013-10-23T13:08:06.760 回答