-1

我有这个项目,我正在做,我需要 C# 结构的帮助。我正在使用控制台应用程序。

我所追求的是创建一个可以在数组中使用的结构。到目前为止,我所拥有的是:

    public struct array
            {
                public static int id;
                public static int x;
                public static int y;
            };
    public static  array[] test = new array[amount];

然后我想要做的是像这样设置变量。

test[i].id = 1;
test[i].x = 1;
test[i].y = 1;

但是它不起作用。如果有人有任何想法,将不胜感激。

谢谢亚当

4

2 回答 2

4

您需要将字段设为非static.
static字段与类型相关联;不是每个实例。

于 2013-04-21T14:52:34.253 回答
0

解决此问题的另一种方法是:

 array[] test = new array[amount];
        array temp = new array();

        temp.id = 1;
        temp.x = 1;
        temp.y = 1;

        test[i] = temp;

并去除静电。

希望对你有帮助

于 2013-04-21T15:12:39.870 回答