我的理解是,清单和编号;衍生类别不能直接分配给清单和编号;不能直接分配给基类。 但是,它如何允许将同一清单加附和;加固;衍生类别分配到一个可计算、可计算、可计算、可计算、且可计算;基类参数类型。
public class Base
{}
public class Derived : Base
{}
public class Test
{
// inside some method...
List<Derived> someElements;
ReadElements(someElements);
public void ReadElements(List<Base> elements) // this throws compile error
{...}
public void ReadElements(IEnumerable<Base> elements) // this one works
{...}
}
I know that the List
is an implementation of IEnumerable
and support indexing and modifying elements, but I don t seem to understand this part? Can someone please explain?
Thanks.