我有一个这样的类结构:
abstract class Base{}
class Descendant : Base{}我还有另一个类,它需要一个List<Base>类型的列表。我知道我只能将Descendant实例添加到List<Base>中,但我认为在这里保持更强的类型会更好。
从List<Descendant>转换到List<Base>最简单的方法是什么
发布于 2010-12-31 15:58:36
使用LINQ:
List<Descendant> descendants = ...;
descendants.Cast<Base>().ToList();https://stackoverflow.com/questions/4568884
复制相似问题