The problem is that you are passing the array by reference as a more general type. If it was by value it wouldn't be an issue but you can't change the type like that with a parameter passed by reference. The problem is because within the method the argument is an object reference so you could assign any type of object to it. It's supposed to be a double[] when the method completes though, so that is obviously a problem. Take a look at this example:The compiler will not let you do that as it cannot guarantee type safety. You can change the type of a parameter passed by reference to a more specific type with a cast, but not to a less specific type.Code:private void Form1_Load(object sender, EventArgs e) { Double[] arr = new Double[10]; // The parameter would go in as a Double[]... this.PassByRef(ref arr); } private void PassByRef(ref object arr) { // ...and be changed to a string here. That can't be allowed to happen. arr = "Hello World"; }




Reply With Quote