c# - Cannot modify the return value because it is not a variable -


i have class called baserobot:

  var robot2 = new baserobot(0, 0, 0);   private point mhome;   public point home   {       { return mhome; }   } 

that original home created, wanting create new home in program.cs. have following code not work, coming error saying

cannot modify return value becasue not variable.

code:

     robot2.home.x = 1      robot2.home.y = 5;              {                  console.writeline("===new robot @ specified home position===");                 stringbuilder ab = new stringbuilder();                 ab.appendformat("robot#2 has home @ <{0},{0}>.\r\n ", robot2.home.x, robot2.home.y);                 ab.appendformat("it facing {0} ", robot2.orientation);                 ab.appendformat("and @ <{0},{0}>.\r\n", robot2.position.x, robot2.position.y);                 console.writeline(ab.tostring());             } 

how assign new values x , y?

you need set home property directly, best create new point object...

robot2.home = new system.drawing.point(1, 5);//x, y 

also, in order allow need apply set accessor home property...

public point home {     { return mhome; }     set { mhome = value; } } 

if want find out more information of why compiler won't let assignthe value directly x property, check few of answers on here


Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

php - MySQLi multi_query results for later use -