Hi i have to call a method that has this signature:
int MethodName(ref object vIndexKey)
If i try to call it with
String c = "690";
MethodName(ref (object) c);
It doesn't work.
How can i do?
thanks
You need to do it like this:
String c = "690";
object o = (object) c;
MethodName(ref o);
The reason is that the parameter must be assignable by the function. The function could do something like this:
o = new List<int>();
Which is not possible if the underlying type is a string that has been casted to an object during the method call, because the target of the assignment would still be a string and not an object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With