I have a set up like this:
abstract class Foo {} class Bar : Foo {}   and a method elsewhere of this form:
void AddEntries(List<Foo>) {}   I am trying to call this method using a list of objects of type Bar
List<Bar> barList = new List<Bar>() AddEntries(barList);   but this gives me the error:
cannot convert from List<Bar> to List<Foo>
Is there anyway around this problem? I Need to keep the method definition using the abstract class.
You could make your AddEntries generic and change it to this
void AddEntries<T>(List<T> test) where T : Foo {     //your logic  }   Have a look at Constraints on Type Parameters for further information.
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