当你从其他类中建立一个类时,它叫什么?

本文关键字:一个 什么 其他 建立 当你 | 更新日期: 2023-09-27 17:49:40

我最近正在学习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())
    {
    }

当你从其他类中建立一个类时,它叫什么?

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

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"
    {}
}
相关文章: