我现在正在学习如何在C#中使用For循环,但是当我尝试编译程序时,控制台中会出现三个错误,其中一个错误说int没有Lenght的定义(我只是不显示错误,因为它们是葡萄牙语),对为什么会发生这种情况有任何想法吗?
using System;
namespace Giraffe
{
class Program
{
static void Main(string[] args)
{
int luckyNumbers = {4, 8, 15, 16, 23, 42};
for (int i = 0; i < luckyNumbers.Length; i++)
{
Console.WriteLine(luckyNumbers[i]);
}
Console.ReadLine();
}
}
}
您的数组声明不正确,将其更改为
You current declaration
int luckyNumbers = {4, 8, 15, 16, 23, 42};
is invalid, you can't assign an array instance toint
variable, thereforeLength
property isn't available