Recasting to base class in C# -


in following c# setup class derived class x , method getting list of list parameter,

class x  {...};  class : x {...};  list<a> lista; list<x> listx;  void somemethod(ref list<x>) {...}; 

is there way use same method class (which derived x)? recasting list x seems not work.

somemethod(ref listx); // works somemethod(ref (list<x>)lista); // not work 

actually, work because ienumerable covariant on generic type parameter.

if modify signature this:

void somemethod(ref ienumerable<x>) {...}; 

then can pass list<x> or list<a> , fine.

as total aside, weird passing ref. don't pass reference types way.


Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -