R
Ralf Propach
Hi,
I have classes A1 and A2 which implement the interface IA.
Now I need a method m that works on Lists of objects of either class.
So I wrote something like
void m(List<IA> myList)
{
// do something with myList
}
and wanted to call it like this
main()
{
List<A1> list = new List<A1>();
// fill list
m(list); // <===
// more code
}
Then the compiler complains about the call m(list); with the error
CS1503: cannot convert from 'System.Collections.Generic.List<A1>'
to 'System.Collections.Generic.List<IA>'.
I can use ArrayLists instead of the List<>'s and the problem goes away,
but I have not found a solution using generic collections.
Any suggestions?
TIA
Ralf
I have classes A1 and A2 which implement the interface IA.
Now I need a method m that works on Lists of objects of either class.
So I wrote something like
void m(List<IA> myList)
{
// do something with myList
}
and wanted to call it like this
main()
{
List<A1> list = new List<A1>();
// fill list
m(list); // <===
// more code
}
Then the compiler complains about the call m(list); with the error
CS1503: cannot convert from 'System.Collections.Generic.List<A1>'
to 'System.Collections.Generic.List<IA>'.
I can use ArrayLists instead of the List<>'s and the problem goes away,
but I have not found a solution using generic collections.
Any suggestions?
TIA
Ralf