when replacing arrays of type A (A[]
) by generic lists (List <A>
), combined with following inheritance
A : B
(A is inherited from B)
and having by ref parameter, the following code doesn't compile any more :
class MyGenericList:
{
HandleListB( ref List<B> list)
{
..
}
HandleListA( ref List<A> list)
{
...
HandleListB( ref list )
}
}
results to: Error CS1503 Argument 2: cannot convert from 'ref System.Collections.Generic.List' to 'ref System.Collections.Generic.List'
whereas this code gets compiled properly:
class MyArray:
{
HandleListB( ref B[] list)
{
..
}
HandleListA( ref A[] list)
{
...
HandleListB( ref list )
}
}
- can anyone explain the different inheritance behaviour between Generic Lists and Arrays in this case?
- and is there a way to solve this problem (the example simplifies the real problem, there are many imvovations of HandleListB( ref list ) throughout my whole project, resulting in many compilation errors when replacing arrays by generic lists..) ?