【发布时间】:2016-09-16 11:38:55
【问题描述】:
namespace text_test
{
public class txt_program
{
public class txt
{
/* 0 */
int[] M_array_0 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
/* 1 */
int[] M_array_1 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
/* 2 */
int[] M_array_2 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
/* 3 */
int[] M_array_3 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
/* 4 */
int[] M_array_4 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
/* 5 */
int[] M_array_5 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
/* 6 */
int[] M_array_6 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
/* 7 */
int[] M_array_7 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
/* 8 */
int[] M_array_8 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
/* 9 */
int[] M_array_9 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
/* 10 */
int[] M_array_10 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
/* 11 */
int[] M_array_11 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
/* 12 */
int[] M_array_12 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
/* 13 */
int[] M_array_13 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
int[][] M = { M_array_0, M_array_1 };
}
}
}
出现与该部分相关的错误:
int[][] M = { M_array_0, M_array_1 };
错误涉及上面的 M_array_0 和 M_array_1。我不明白的是为什么我不能从上面创建一个多维数组。我应该使用该代码吗? 我试过了:
string[][] M = { M_array_0, M_array_1 };
double[][] M = { M_array_0, M_array_1 };
错误显示:
字段初始值设定项无法引用非静态字段、方法或属性 'txt_program.txt.M_array_0' text_test \psf\Home\Documents\Visual Studio 2015\Projects\text_test\text_test\text.cs 45 Active
提前谢谢你。
【问题讨论】:
-
你应该在constructor中设置这些变量。
-
如果你将数组设为静态,这将起作用。
-
我重新打开了这个问题,因为它看起来更多的是关于创建锯齿状数组而不是发生的错误。