Cannot modify the return value because it is not a variable

前端 未结 7 1755
庸人自扰
庸人自扰 2020-12-11 19:27

I have a class called BaseRobot:

  var robot2 = new BaseRobot(0, 0, 0);
  private Point mHome;
  public Point Home
  {
      get { return mHome;         


        
7条回答
  •  被撕碎了的回忆
    2020-12-11 19:49

    You need to set the Home property directly, usually best to create a new Point object...

    robot2.Home = new System.Drawing.Point(1, 5);//x, y
    

    Also, in order to allow that you need to apply a set accessor to your Home property...

    public Point Home
    {
        get { return mHome; }
        set { mHome = value; }
    }
    

    If you want to find out some more information of why the compiler won't let you assignthe value directly to the X property, then check a few of the answers over here

提交回复
热议问题