C# 修饰符';XXXX和x27;对于此项目无效

C# 修饰符';XXXX和x27;对于此项目无效,c#,static,C#,Static,有人知道我为什么会出现这些错误吗: 修饰符“static”对此项无效 修饰符“readonly”对此项无效 在以下代码的第3行: public class YYY { private static readonly struct ZZZ { private int x = 0; private int y = 0; private int z = 0; } } 当我研究这个问题时,我只找到了我不太了解的接口的答案,但我只想

有人知道我为什么会出现这些错误吗:

修饰符“static”对此项无效

修饰符“readonly”对此项无效

在以下代码的第3行:

public class YYY
{
    private static readonly struct ZZZ
    {
        private int x = 0;
        private int y = 0;
        private int z = 0;
    }
}

当我研究这个问题时,我只找到了我不太了解的接口的答案,但我只想在我的类中创建一个静态只读结构字段。

static
readonly
都是仅在对象实现中使用的修饰符,而不是在定义中。声明将要使用的
ZZZ
struct对象时,此时可以添加修饰符
static
readonly

public class YYY
{
    private struct ZZZ
    {
        private int x = 0;
        private int y = 0;
        private int z = 0;
    }

    private static readonly ZZZ myZZZ = new ZZZ(); //The declaration of a ZZZ instance.
}