I am preparing for the microsoft exam about C # 70-483, "still a long way" and after the C # plural. After running the test and checking for my incorrect answers, I came up with this.
2. Consider the following code:
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));
}
}
}
When does a variable go out of scope? Answers:
When exiting the method ListTowns().
Upon exiting foreach loop
I never go out of scope because of the method static.
Upon exiting for loop
The correct answer is 4, but my answer is 2. Because after the for u loop, you can still use i. Or is my definition of βout of scopeβ incorrect?
source
share