foreach的错位
static void Main(string[] args)
{
int[] num = new int[] { 3, 34, 43, 2, 11, 19, 30, 55, 20 };
bool hasit = false;
for (int i = 0; i < num.Length; ++i)
{
if (num[i] % 7 == 0)
{
hasit = true;
break;
}
}
if (hasit)
{
Console.Write("有七的倍数");
}
else
{
Console.Write("没有七的倍数");
}
}
}
如图代码,把for语句换成foreach, if (num[i] % 7 == 0)这一句就会报错,请问为什么呀