这是什么错误,怎么用了属性反而不好用
今天碰到一个错误,很奇怪,不是很清楚,
下面是代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Person Tom = new Person();
Tom.Show();
}
}
public class Person
{
private CellLine[] rowLines;
public Person()
{
rowLines = new CellLine[1];
rowLines[0] = new CellLine();
rowLines[0].BeginPoint = new Point(1, 1);
}
public void Show()
{
rowLines[0].beginPoint.X = 99;//没错
//错误: 无法修改“ConsoleApplication1.CellLine.BeginPoint”的返回值,因为它不是变量
rowLines[ 0].BeginPoint.X = 99;
rowLines[ 0].BeginPoint = new Point(1, 1);//也没错
}
};
public class CellLine
{
public Point BeginPoint { get { return beginPoint; } set { beginPoint = value; } }
public Point beginPoint = new Point(0, 0);
};
}