12
Reply

no polymorphism with references ?

loogel

loogel

Oct 29 2004 2:08 AM
4.2k
I am not sure why the following does not work class obj {...} class rocks : obj {...} static int func(ref obj [] list) {...} static void Main(string[] args) { rock []rocks = new rock[10]; {...} //initialize func(ref rocks).ToString()); } it returns the error: "[...] Argument '1': cannot convert from 'ref Polymorphism_ref_test.Class1.rock[]' to 'ref Polymorphism_ref_test.Class1.obj[]'" but this does (the difference is that the argument is not a reference anymore): class obj {...} class rocks: obj {...} static int func(obj [] list) {...} static void Main(string[] args) { rock []rocks = new rock[10]; {...} //initialize funk(rocks); } can anyone tell me why this does not work ?

Answers (12)