法Ref对象参数 [英] method with ref object parameter
本文介绍了法Ref对象参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好我有打电话给具有此签名的方法:
Hi i have to call a method that has this signature:
int MethodName(ref object vIndexKey)
如果我尝试调用它。
String c = "690";
MethodName(ref (object) c);
这是行不通的。
我该怎么办?
感谢
推荐答案
您需要做的是这样的:
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.
这篇关于法Ref对象参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文