我有List和對象的字符串和雙打,我嘗試根據itemtype和它們的值調用不同的方法。在調試器中,我可以看到第一次迭代工作正常,但是在調用方法後第二次進入時出現錯誤。
如果我註釋掉這些方法並將其應用於一些簡單的方法,那麼我就會明白它與我如何調用這些方法有關。在對象foreach中調用方法時出錯
我該怎麼做,我該怎麼做才能使它工作?
如果有更簡單的方法來做我想要的,請讓我知道。
public double evaluateExpressionUsingVariableValues(List<Object> anExpression, Dictionary<String, double> variables)
{
foreach (object element in anExpression)
{
if(element.GetType()!=typeof(string))
{
setOperand((double)element);
}
else if (element.GetType() == typeof(string))
{
if (!element.ToString().StartsWith("%"))
performOperation((string)element);
else
setOperand(variables[element.ToString()]);
}
}
return this.operand;
}
你能告訴你在哪一行哪個錯誤? – 2011-02-18 23:49:18
拋出什麼異常?你確定列表中的所有對象都是字符串還是雙精度? – 2011-02-18 23:49:46