嗯,我坚持使用未分配的本地变量。我首先声明我的变量并创建我的字典。使用未分配的本地变量字典
下面我的代码:
string berichtAantalMunten;
double[] munten = { 2,1,0.50,0.20,0.10,0.05};
Dictionary<double, int> aantalMunten = new Dictionary<double, int>();
int muntenTeller = 0;
double bedragTerug = totaalIngeworpen - prijsDrankje;
foreach (double munt in munten){
double tijdelijkIngeworpen = totaalIngeworpen - munt;
if (tijdelijkIngeworpen >= 0)
{
muntenTeller++;
aantalMunten.Add(munt, muntenTeller);
totaalIngeworpen = tijdelijkIngeworpen;
}
}
if (aantalMunten.ContainsKey(2))
{
berichtAantalMunten = aantalMunten[2].ToString() + " x € 2,00\n";
}
if (aantalMunten.ContainsKey(1))
{
berichtAantalMunten += aantalMunten[1].ToString() + " x € 1,00\n";
}
你应该给我们更多关于编译错误的信息。哪一行有错误?哪个变量正在抱怨? – 2014-11-21 09:52:42
@AndrewShepherd明显是“berichtAantalMunten”应该增加的最后一个 – HimBromBeere 2014-11-21 09:54:14