请考虑以下代码。
using System.Drawing;
public class Element
{
public static Point position1;
private static Point position2;
public static Point Position2
{
get { return position; }
set { position = value; }
}
}
class Drawing
{
public Drawing()
{
Element.position1.X = 0; //Correct
Element.Position2.X = 0; //Incorrect
}
}
为什么不能通过position2.X
更改Element.Position2.X
的值?
因此我不得不这样做:
Point newPoint = new Point (0, 0);
Element.Position2 = newPoint;
//Or : Element.Position2 = new Point (0, Element.Position2.Y);
position2.X
一样使用position1.X
来访问Element.Position2.X
的值,而是使用# cat installdirs/Dir1
host1
host2
?答案 0 :(得分:-2)
正确定义公共或私人运营商
public class Element
{
private static Point position1;
private static Point position2;
public static Point Position1
{
get { return position1; }
set { position1 = value; }
}
public static Point Position2
{
get { return position2; }
set { position2 = value; }
}
}