我正准备参加关于c#70-483的微软考试,"还有很长的路要走", 并遵循复数视频的C#路径.在完成测试并检查我的错误答案后,我来到了这个.
2.考虑以下代码:
static void ListTowns(string[] countries)
{
foreach (string country in countries)
{
int townCount = GetTownCount(country);
int i = 0;
for (i = 0; i < townCount; i++)
{
Console.WriteLine(GetTownName(country, i));
}
}
}
Run Code Online (Sandbox Code Playgroud)
变量何时超出范围?回答:
退出ListTowns()方法.
退出时 foreach loop
我永远不会超出范围,因为方法是static.
退出时 for loop
正确答案是4,但我的答案是2.因为在for循环之后你仍然可以使用i.或者我对"超出范围"的定义不正确?