美文网首页
Constructor

Constructor

作者: 津涵 | 来源:发表于2019-02-02 09:28 被阅读0次

    this:继承同一类中的其它构造函数

    Class Car
    {
    private string _description;
    private uint _nwheels;
    public Car(string description,uint nwheels)
    {
    _description = description;
    _nwheels = nwheels;
    }
    public Car(string descripton):this(description,4)
    {
    //coding
    }
    }
    注:(1)The two-parameter constructor executes before any code in the body of the one-parameter constructor
    (2)The 'this' keyword simply causes the constructor with the nearest matching parameters to be called

    base:(继承使用)基类构造函数

    It is not possible to put more than one call in the initializer.

    A static no-parameter constructor for a class.

    class MyClass
    {
    static MyClass()
    {
    }
    }
    注:(1)Such a constructor is executed only once, unlike the constructors written so far, which are instance constructors that are executed whenever an object of that class is created.
    (2)One reason for writing a static constructor is if your class has some static fields or properties that need to be initialized from an external source before the class is first used

    相关文章

      网友评论

          本文标题:Constructor

          本文链接:https://www.haomeiwen.com/subject/vlxssqtx.html