int[] num = new int[] { 3, 34, 43, 2, 11, 19, 30, 55, 20 };
bool has = false;
for(int x =0;x<num.Length ; x++)
//foreach (var x in num)
{
if (x % 7 == 0)
{
has = true;
break;
}
}
if (has)
{
Console.WriteLine("有七的倍数");
}
else
{
Console.WriteLine("没有七的倍数");
}
foreach(int x in num);
是int型
题主在运行for循环是if内的判断条件错了,应该为num[x]才对!而在运行foreach时就可以引用 x 来代替num[x]!