loogel

loogel

  • NA
  • 17
  • 0

no polymorphism with references ?

Oct 29 2004 2:08 AM
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)