无效的排名说明符(c#数组)

时间:2010-06-24 09:49:03

标签: c# arrays

我对我定义的数组有点麻烦。

int[] levelData = new int[450] {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};

从我读过的所有教程和网页中,我发现它没有任何问题。 Visual C#给出的错误是:

“无效的排名说明:预期'['或','”

它给我的列号指向第二个数字。

关于什么是错的任何想法?这让我疯狂了几个小时。

3 个答案:

答案 0 :(得分:2)

您是否尝试过没有数字450,即int[] levelData = new int[] {,因为编译器应该能够自动扣除长度(也许它甚至想要这样做,即你不应该在你的时候放一个大小使用初始化器?)。

答案 1 :(得分:0)

您发布的代码在VS2008和VS 2010中运行良好。所以看起来您没有发布正确的内容。如果您获得无效的排名说明,那么初始化阵列的方式可能是错误的。

通过此MSDN链接http://msdn.microsoft.com/en-us/library/b6ax0bze(VS.80).aspx

查看哪些内容尚未成功

答案 2 :(得分:0)

你粘贴的声明对我来说很好。你确定错误出现在这一行,而这正是你的代码吗?

这种情况的一个常见原因是您没有初始化数组中的所有元素。确保你有450。