类、结构或接口成员声明中的无效标记“=”

Invalid token '=' in class, struct, or interface member declaration

我有这门课:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ComputerGraphicsExercises
{
    class Adamak
    {
        public int BodyX1;
        public int BodyX2;
        public int HeadX;
        public int LeftArmX1;
        public int LeftArmX2;
        public int RightArmX1;
        public int RightArmX2;
        public int LeftLegX1;
        public int LeftLegX2;
        public int RightLegX1;
        public int RightLegX2;
        public int LeftEyeX;
        public int RightEyeX;
        public int PupilOfLeftEyeX;
        public int PupilOfRightEyeX;
        public int NoseX;
        public int LipsX;
        public int HairX;
        public int LeftEarX;
        public int RightEarX;

        public int BodyY1;
        public int BodyY2;
        public int HeadY;
        public int LeftArmY1;
        public int LeftArmY2;
        public int RightArmY1;
        public int RightArmY2;
        public int LeftLegY1;
        public int LeftLegY2;
        public int RightLegY1;
        public int RightLegY2;
        public int LeftEyeY;
        public int RightEyeY;
        public int PupilOfLeftEyeY;
        public int PupilOfRightEyeY;
        public int NoseY;
        public int LipsY;
        public int HairY;
        public int LeftEarY;
        public int RightEarY;
    }
}

然后我这样声明了一个变量:

namespace ComputerGraphicsExercises
{
    public partial class Main : Form
    {
        Adamak iMan2 = new Adamak();
    }
}

现在我想更改以下值:

iMan2.BodyX1 = 50;

但我得到这个错误:

Error 1 Invalid token '=' in class, struct, or interface member declaration C:\vc\ComputerGraphicsExercises\ComputerGraphicsExercises\Main.cs 17 22 ComputerGraphicsExercises

我的错误是什么?

您在任何构造函数或方法之外为 class 实例的字段赋值。这就是为什么