我有这个代码:
foreach(List<string> build in Builds)
{
int i = 0;
foreach(string item in build)
{
switch (i)
{
case 0:
Console.WriteLine("BuildID: " + item);
break;
case 1:
Console.WriteLine("UserID: " + item);
break;
case 2:
Console.WriteLine("Parameter 1: " + item);
break;
case 3:
Console.WriteLine("Parameter 2: " + item);
break;
case 4:
Console.WriteLine("Parameter 3: " + item);
break;
case 5:
Console.WriteLine("Parameter 4: " + item);
break;
}
i++;
Console.WriteLine(i);
}
}
输出是:
BuildID: 1
1
BuildID: 1
1
BuildID: a
1
BuildID: b
1
BuildID: c
1
BuildID: d
1
列表中的项目正在递增并正确显示(1,1,a,b,c,d)但由于我不知道的原因,在开关执行后忘记了“i”计数器的递增?我不明白?预期的输出应该是:
BuildID: 1
1
UserID: 1
2
Parameter 1: a
3
Parameter 2: b
4
Parameter 3: c
5
Parameter 4: d
6