如何声明和在C#中使用数组 [英] How to declare and use arrays in C#
问题描述
我有C#数组一个看似基本的问题。我是初学者,但是这是一个的真正的基本问题,它已经有我结了半个多小时了。我使用C#2010前preSS。
I have a seemingly basic problem with C# arrays. I am a beginner, but this is a really basic problem and it has had me in knots for more than half an hour now. I am using C# 2010 Express.
这code: -
string[] motionCam = new string[8];
motionCam[1] = "Stop";
报告错误:
数组大小不能在变量声明中指定(试
以新的前pression初始化)
Array size cannot be specified in a variable declaration (try initializing with a 'new' expression)
甚至连基本的数组的例子我复制和粘贴过的教育网站报告同样的错误,我不知道为什么。
Even basic array examples I copy and paste off of education web sites report this same error and I have no clue why.
推荐答案
当你粘贴的code是有效的,你的问题是别的东西。结果
也许你在类一级宣布它。
While the code you pasted is valid, your problem is something else.
Maybe you declared it in the class level.
motionCam [1] =停止;
是一个赋值不是一个声明,这究竟是为什么编译器喊声
motionCam[1] = "Stop";
is an assignment not a declaration, this why the compiler shouts.
请参阅谁曾是同样的问题,有人这样问题。
底线是您不能在类级别非声明语句。
这篇关于如何声明和在C#中使用数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!