class mytest { public mytest():this("user") {} //应该还有个这个东西吧,这是重载构造函数 public mytest(string abc) {}}
一个构造函数调用它本身所在类的另一个构造函数。 class mytest { public mytest():this("user") { mytest("user"); } // public mytest(string abc) {} }也可以在实例给时直接 mytest t = new mytest("user");
就是构造函数重载,代码就像楼上的,借用一下,嘿嘿 class mytest { public mytest():this("user") { mytest("user"); } // public mytest(string abc) {} } 就是说如果你实例化这个类的时候 mytest t = new mytest("123"); 就调用public mytest(string abc)这个构造函数, 如果是 mytest t = new mytest();呢 就调用public mytest():this("user")给mytest的构造函数一个默认的参数user
{
public mytest():this("user")
{}
//应该还有个这个东西吧,这是重载构造函数
public mytest(string abc)
{}}
class mytest
{
public mytest():this("user")
{
mytest("user");
}
//
public mytest(string abc)
{}
}也可以在实例给时直接 mytest t = new mytest("user");
class mytest
{
public mytest():this("user")
{
mytest("user");
}
//
public mytest(string abc)
{}
}
就是说如果你实例化这个类的时候
mytest t = new mytest("123");
就调用public mytest(string abc)这个构造函数,
如果是
mytest t = new mytest();呢
就调用public mytest():this("user")给mytest的构造函数一个默认的参数user