我和if和for循环有问题。第一个结束括号(})关闭第一个if语句。我想要做的是关闭与之对齐的支架。
startnum = int.Parse(startnumbers);
endnum = int.Parse(endnumbers);
string route = "1. ";
if (startletters == endletters && startnum > endnum)
{
for (int count = 0; startnum < endnum; startnum++)
{
if (startname != endname)
{
count++;
route += ("Board the {0} line, go {1} stops toward {2}",startletters,count, endname );
}
}
}
答案 0 :(得分:3)
您在这行中有语法错误:
route += ("Board the {0} line, go {1} stops toward {2}",startletters,count, endname );
您具有string.Format
的参数,但实际上并未调用它。您要改为:
route += string.Format("Board the {0} line, go {1} stops toward {2}", startletters, count, endnum);
由于语法错误,编译器无法按预期匹配花括号。
答案 1 :(得分:1)
您将要犯的以下错误:
如何解决?
您的代码[已更正]:
startnum = int.Parse(startnumbers);
endnum = int.Parse(endnumbers);
string route = "1.";
if (startletters == endletters && startnum > endnum)
{
for (int count = 0; startnum < endnum; startnum++)
{
if (startname != endname)
{
count++;
string tempRoute = string.Format("Board the {0} line, go {1} stops toward {2}",startletters,count, endname);
route = route + " " + tempRoute;
}
}
}