我有一堂课叫BaseRobot
:
var robot2 = new BaseRobot(0, 0, 0);
private Point mHome;
public Point Home
{
get { return mHome; }
}
那是创建原始房屋的地方,我想在program.cs
. 我有以下代码,但它不起作用,它出现了一个错误说
无法修改返回值,因为它不是变量。
代码:
robot2.Home.X = 1
robot2.Home.Y = 5;
{
Console.WriteLine("===New robot at specified home position===");
StringBuilder ab = new StringBuilder();
ab.AppendFormat("Robot#2 has home at <{0},{0}>.\r\n ", robot2.Home.X, robot2.Home.Y);
ab.AppendFormat("It is facing {0} ", robot2.Orientation);
ab.AppendFormat("and is currently at <{0},{0}>.\r\n", robot2.Position.X, robot2.Position.Y);
Console.WriteLine(ab.ToString());
}
如何为 x 和 Y 分配新值?