my function has the following signature
function myfunction(ref object)
I use it as such
Array arr = Array.CreateInstance(System.Type.GetType("System.String"), 2);
arr.SetValue("1", 0);
myfunction( ref arr);
And I am getting
“cannot convert from ‘ref System.Array’ to ‘ref object'”
I was under the impression that System.Array is object …so why am I getting this error? Is object different from Object?
Think of ‘ref object’ as “I take a reference to a variable that can store an Object”. Suppose that ‘myfunction’ tried to store an ‘int’ to the variable you passed? This would fail at runtime, which is undesirable.
On a side note, you can use typeof(string) in place of calling GetType(“System.String”). You can also just say:
To access the array first, you can do this:
I would double check that you’re using the method myfunction correctly; it’s a rather unusual parameter type for taking an initialized array.