I have a class structure like this:
abstract class Base{}
class Descendant : Base{}
I have another class that needs a list of type List<Base>. I know I can just add Descendant instances to a List<Base> but I'd think it'd be preferable to keep stronger-typing here.
What is the easiest way of casting from List<Descendant> to List<Base>?
Use LINQ:
List<Descendant> descendants = ...;
descendants.Cast<Base>().ToList();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With