-1

我最近在学习 C# 并了解基础知识。我不是在下面写这段代码,而是试图理解它。line 类在声明 start 和 end 字段时使用 Point。这在 C# 中叫什么?

public class Point
{
    private float x;

    public float X
    {
        get { return x; }
        set { x = value; }
    }
    private float y;

    public float Y
    {
        get { return y; }
        set { y = value; }
    }

    public Point(float x, float y)
    {
        this.x = x;
        this.y = y;
    }

    public Point():this(0,0)
    {
    }

   }

}

class Line
{
    private Point start;

    public Point Start
    {
      get { return start; }
      set { start = value; }
    }

    private Point end;

    public Point End
    {
      get { return end; }
      set { end = value; }
    }

    public Line(Point start, Point end)
    {
        this.start = start;
        this.end = end;
    }

    public Line():this(new Point(), new Point())
    {
    }
4

1 回答 1

2

我不确定你在问什么,但我想你想知道正确的术语:

public class Point // a class (obviously)
{
    private float x; // private field; also the backing
                     // field for the property `X`

    public float X // a public property
    {
        get { return x; }  // (public) getter of the property
        set { x = value; } // (public) setter of the property
                           // both are using the backing field
    }


    public float Y // an auto-implemented property (this one will
    { get; set; }  // create the backing field, the getter and the
                   // automatically, but hide it from accessing it directly)

    public Point(float x, float y) // constructor
    {
        this.x = x;
        this.Y = y;
    }

    public Point()  // a default constructor that calls another by
        : this(0,0) // using an "instance constructor initializer"
    {}
}
于 2012-12-27T01:46:21.397 回答