比如如下代码,应该怎么创建这个list才对呢class a(){
public Create(){
var lst = new List<this.GetType()>(); //编译错误
}
}class b() : a{}foo(){
var f=new b(); b.Create();
}
public Create(){
var lst = new List<this.GetType()>(); //编译错误
}
}class b() : a{}foo(){
var f=new b(); b.Create();
}
----------仅供参考
{
Type generic = typeof(List<>);
var list = Activator.CreateInstance(generic.MakeGenericType(this.GetType())) as IList;
}
用反射可以实现你这个需求,但就像LS说的,这种设计可能不是很好。