using System;
namespace Construture
{
class Demo
{
[STAThread]
static void Main(string[] args)
{
Child c = new Child(10,20,30);
}
}
public class Parent
{
public Parent(int i)
{
Console.WriteLine("Parent with 1 paramenter:"+i);
}
}
public class Child : Parent
{
public Child(int i,int j):base(j)
{
Console.WriteLine("Child with 2 parameters:"+i);
Console.WriteLine("Child with 2 parameters:"+j);
}
public Child(int i,int j,int k):this(j,k)
{
Console.WriteLine("Child with 3 parameters:"+i);
Console.WriteLine("Child with 3 parameters:"+j);
Console.WriteLine("Child with 3 parameters:"+k);
}
}
}
namespace Construture
{
class Demo
{
[STAThread]
static void Main(string[] args)
{
Child c = new Child(10,20,30);
}
}
public class Parent
{
public Parent(int i)
{
Console.WriteLine("Parent with 1 paramenter:"+i);
}
}
public class Child : Parent
{
public Child(int i,int j):base(j)
{
Console.WriteLine("Child with 2 parameters:"+i);
Console.WriteLine("Child with 2 parameters:"+j);
}
public Child(int i,int j,int k):this(j,k)
{
Console.WriteLine("Child with 3 parameters:"+i);
Console.WriteLine("Child with 3 parameters:"+j);
Console.WriteLine("Child with 3 parameters:"+k);
}
}
}
没有加析构函数,只要把析构理解为上面的反向就行了。
同事主要问我,:this(some parameter)和base(some parameter)是什么意思。我也没告诉他们,作了这么一个demo,自己运行一下,就知道接过了。如果愿意的话,F11跟踪每一步,效果会更好一些。