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
网友评论