我在基类中有一个方法,它应该返回类型为derivation类型的自实例。例如:如何从基类型中声明的方法返回派生类型
class A
{
public string X { get; set; }
public A SetX(string x)
{
this.X = x;
return this;
}
}
class B:A
{
public string Y { get; set; }
public B SetY(string y)
{
this.Y = y;
return this;
}
}
然后我想,如下流利调用方法:
B b = new B();
b.SetX("x")
.SetY("y");
但这里SetX
回报A型,和A has'nt命名SetY
任何方法。我如何设计这样的功能?
http://en.wikipedia.org/wiki/Curiously_recurring_template_pattern – SLaks 2013-04-21 02:12:11