-1

私はごく最近 C# を学んでおり、基本を理解しています。以下にこのコードを書いているわけではありませんが、理解しようとしています。line クラスは、開始フィールドと終了フィールドを宣言するときに 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 に答える