Code
public class Person
{
public Person():this(null)
{
Console.WriteLine("aaaaaaaaaa");
}
public Person(string name)
{
if (name == null)
{
Console.WriteLine("name is null");
}
else
{
Console.WriteLine(name);
}
}
注:Person p=new Person(),这样实例化时,先通过this关键字,调用有参数的构造函数,然后调用自己。
输出结果:
name is null
aaaaaaaaaa