在创建实例的时候通过构造函数调用构造函数里面的方法只是构造函数其中的一个作用.
在我看来,构造函数的大部分作用是在做参数传递.下面的这个例子说明:
class Vehicle
{
public Vehicle()
{
}
public Vehicle(string model)
{
this.model = model;
}
public Vehicle(string wheel, string color, string model)
:this(model)
{
this.wheel = wheel;
this.color = color;
}
protected string wheel;
public string Wheel
{
get { return wheel; }
set { wheel = value; }
}
private string color;
public string Color
{
get { return color; }
set { color = value; }
}
private string model;
public string Model
{
get { return model; }
set { model = value; }
}
}}
每天的作业都交到这里.