假设我们有这两个类:
public class Derived : Base
{
public Derived(string s)
: base(s)
{ }
}
public class Base
{
protected Base(string s)
{
}
}
那么在Base中如何得到Derived类的类型呢?答案是使用:this.GetType()
就像如下
class Base
{
public Base()
{
Console.WriteLine("Base Constructor. Calling type: {0}", this.GetType().Name);
}
}