2013-10-25 45 views
0

我收到一個我找不到的錯誤。我想谷歌和SO,但無濟於事...循環訪問Dictionary對象'variableName'是一個'變量',但像'method'一樣使用

這裏是我的代碼:

for (int i = 0; i <= dctConvertedJSON.GetUpperBound(0); i++) 
{ 
    foreach (KeyValuePair<string, string> kvp in dctConvertedJSON(i)) 
    { 
     string strKey = kvp.Key; 
     string strValue = kvp.Value; 
     Debug.WriteLine("Key: " + strKey.ToString + Constants.vbTab + " Value: " + strValue); 
    } 
} 

foreach我得到一個錯誤的dctConvertedJSON曰:

Error: 'dctConvertedJSON' is a 'variable' but is used like a 'method'

我在做什麼(或不做)導致此錯誤?

回答

4

你應該把它糾正到:

dctConvertedJSON[i] 

因此,代碼是:

for (int i = 0; i <= dctConvertedJSON.GetUpperBound(0); i++) 
{ 
    foreach (KeyValuePair<string, string> kvp in dctConvertedJSON[i]) 
    { 
     string strKey = kvp.Key; 
     string strValue = kvp.Value; 
     Debug.WriteLine("Key: " + strKey.ToString() + Constants.vbTab + " Value: " + strValue); 
    } 
} 
+1

唉唉!這就是我成爲一名VB開發人員這麼多年了!謝謝 – FastTrack