遍历字典对象“变量名”是一个“变量”,但像“方法”一样使用
本文关键字:变量名 但像 方法 一样 对象 字典 遍历 一个 变量 | 更新日期: 2023-09-27 18:36:52
我收到一个我无法弄清楚的错误。我尝试了谷歌和SO,但无济于事...
这是我的代码:
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'
我正在做什么(或不做什么)导致此错误?
您应该将其更正为:
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);
}
}