主题:这段代码为什么不能这样写?
最外面的IF为什么不能写else呢?写了程序也不执行?真的郁闷!
public void buyFilm(string filmname)//string filmname
{
Dictionary<string, Film> inventory = new Dictionary<string, Film>();
foreach (string s in inventory.Keys)
{
if (s==filmname)
{
if (inventory[s].Amount > 0)
{
inventory[s].Amount--;
break;
}
else
{
string ss = string.Format("《{0}》现在没货", filmname);
Console.WriteLine(ss);
break;
}
}
[color=FF00FF] else
{
string sr = string.Format("本店没有《{0}》", filmname);
Console.WriteLine(sr);
break;
}[/color] }
writeFilms();
}
public void buyFilm(string filmname)//string filmname
{
Dictionary<string, Film> inventory = new Dictionary<string, Film>();
foreach (string s in inventory.Keys)
{
if (s==filmname)
{
if (inventory[s].Amount > 0)
{
inventory[s].Amount--;
break;
}
else
{
string ss = string.Format("《{0}》现在没货", filmname);
Console.WriteLine(ss);
break;
}
}
[color=FF00FF] else
{
string sr = string.Format("本店没有《{0}》", filmname);
Console.WriteLine(sr);
break;
}[/color] }
writeFilms();
}