本文介绍了列表与LT; T>遗产的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 大家好,我有一个经典问题:List< Tand List< Xwhere X是X类: T. 好的,我知道问题:我如果X 是T,列表< Xis不是列表< T>,那么我不知道是什么解决方案:) 让我们看看这个场景(显然没有编译): // ---- ---------------------- class BaseClass {} class DerivedClass:BaseClass {} class BaseClassCollection:List< BaseClass> {} class DerivedClassCollection:List< DerivedClass> {} class Collector { BaseClassCollection _classes = new BaseClassCollection(); 公共虚拟BaseClassCollection类 { get {return _classes; } } } 类DerivedCollector:收藏家 { public override DerivedClassCollection类 { get {return _classes; } } } // --------------------- ----- 这就是我所拥有的:更基于类的更具体的类。 什么是更类似的解决方案? /> 谢谢!Hi all, I have a classic problem: List<Tand List<Xwhere X is a class X :T.Ok, I know the problem: I cannot cast List<Ton List<Xbecause also if Xis a T, List<Xis not a List<T>.What I don''t know is the solution :)Let''s see this scenario (that obviously doesn''t compile):// --------------------------class BaseClass{ }class DerivedClass : BaseClass{ }class BaseClassCollection : List<BaseClass>{ }class DerivedClassCollection : List<DerivedClass>{ }class Collector{BaseClassCollection _classes = new BaseClassCollection();public virtual BaseClassCollection Classes{get { return _classes; }}}class DerivedCollector : Collector{public override DerivedClassCollection Classes{get { return _classes; }}}// --------------------------This is what I would have: more specific classes that work on base classes.What is the more similar solution?Thanks!推荐答案 这篇关于列表与LT; T>遗产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-14 12:12